[英]getElementById does not work in IE if NAME attribute is not specified (Javascript, HTML5 and Internet Explorer)
I have this problem of an image rollover javascript not working in Internet Explorer if I don't specify the NAME attribute in the tag. 如果我没有在标记中指定NAME属性,就会遇到图像翻转JavaScript无法在Internet Explorer中运行的问题。 The other problem is when I do, the HTML5 validator will come up with a message saying "NAME attr is obsolete, use ID instead" which is what I am using with getElementById. 另一个问题是,当我这样做时,HTML5验证器将显示一条消息,指出“ NAME attr已过时,请改用ID”,这是我与getElementById一起使用的内容。
Should I specify a NAME attribute anyway and ignore the error messages or is there a workaround? 我是否仍应指定NAME属性并忽略错误消息,或者有解决方法? I don't wish to add extra attributes if I don't have too. 如果没有,我也不想添加额外的属性。
Thanks 谢谢
Adam 亚当
You aren't calling getElementById
; 您没有在调用getElementById
; you're writing document[img_name]
. 您正在编写document[img_name]
。
Don't. 别。
Check to make sure you do not have duplicate ids. 检查以确保您没有重复的ID。 getElementById
incorrectly gets name=""
in certain IEs, if there is no element with the id. 如果没有带有ID的元素,则getElementById
在某些IE中会错误地获取name=""
。
Also, make sure the document is not in quirks mode and is in standards mode. 另外,请确保文档不是处于怪异模式,而是处于标准模式。 alert( document.compatMode )
and make sure it isnt BackCompat. alert( document.compatMode )
并确保它不是BackCompat。 If it is, use a proper doctype and kill comments/whitespace before doctype. 如果是这样,请使用适当的doctype,并在doctype之前取消注释/空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.