本文介绍了JavaScript的问题处理不同的浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我遇到的问题是,我的code正常工作的JavaScript,但无法在Firefox或Safari和奇怪,为什么正常工作。我在做什么是我有一个循环经历的每个元素,并根据一个文本框只是想提醒的东西里面的变量。就像我前面说的这code在IE浏览器工作正常。这里是低于code:

下面是文本框的示例:

 < ASP:文本框ID =txtMac=服务器REQ =YESerrMessage =陆委会/>用于:(a = 0;一个与所述; theForm.elements.length;一个++){
  如果(theForm.elements [A] .TYPE ==文本&放大器;&安培; theForm.elements [A] ==名.req是){
    警报(这里是制造)
  }
}


解决方案

使用阅读自定义属性。请参见。

所以不是

(theForm.elements [A] .TYPE ==文本&放大器;&安培; theForm.elements [A] ==名.req是)

使用

(theForm.elements [A] .getAttribute(类型)==文本&放大器;&安培; theForm.elements [A] .getAttribute('REQ')==是)

The problem that I'm having is that my code works fine in JavaScript but doesn't work correctly in Firefox or safari and wondering why. What I'm doing is I have a loop going through each element and depending on the variable inside a text box just want to alert something. Like i said earlier this code works fine in IE. Here is the code below:

Here is an example of text box:

<asp:TextBox ID="txtMac" runat="server" req="yes" errMessage="Mac"/>

for (a = 0; a < theForm.elements.length; a++) {
  if (theForm.elements[a].type == "text" && theForm.elements[a].req == "yes") {
    alert("Made it here")
  }
}
解决方案

Use getAttribute to read the custom attributes. See http://jsfiddle.net/8EWQr/.

So instead of

(theForm.elements[a].type == "text" && theForm.elements[a].req == "yes")

use

(theForm.elements[a].getAttribute('type') == "text" && theForm.elements[a].getAttribute('req') == "yes")

这篇关于JavaScript的问题处理不同的浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 03:17