开发者

Javascript - proper getAttributeNode on IE6+

开发者 https://www.devze.com 2023-02-03 18:46 出处:网络
I have a regular input box (no onchange attribute). <input type=\"text\" id=\"bar\" name=\"bar\" />

I have a regular input box (no onchange attribute).

<input type="text" id="bar" name="bar" /> 

For some reason, IE6+ does returns [object], while FF and Chrome returns null.

if ((elem.getAttributeNode('onchange')) != null)
  elem.onchange();

I did also try as:

if (typeof(elem.onchange) !== 'undefined')
  elem.onchange(开发者_高级运维);

What would be the proper cross-browser way to check if the element has the attribute?

Thanks


It seems to me that you wish to know if onchange is a function or not, in which case you can just do

if(typeof elem.onchange == 'function')
0

精彩评论

暂无评论...
验证码 换一张
取 消