admin管理员组文章数量:1429553
I have a script that checks the value of a Div Id.
<div id="hour" style="display:none;">2</div>
<div id="min" style="display:none;">1</div>
<div id="sec" style="display:none;">3</div>
hour = document.getElementById("hour").innerHTML;
min = document.getElementById("min").innerHTML;
sec = document.getElementById("sec").innerHTML;
Works in Chrome, but not in Internet Explorer (Which is where I need it to work)
It gives me the error, "Object doesn't support this property or method"
What is the easier way (preferably one line) to get around this?
I have a script that checks the value of a Div Id.
<div id="hour" style="display:none;">2</div>
<div id="min" style="display:none;">1</div>
<div id="sec" style="display:none;">3</div>
hour = document.getElementById("hour").innerHTML;
min = document.getElementById("min").innerHTML;
sec = document.getElementById("sec").innerHTML;
Works in Chrome, but not in Internet Explorer (Which is where I need it to work)
It gives me the error, "Object doesn't support this property or method"
What is the easier way (preferably one line) to get around this?
Share Improve this question asked Nov 28, 2011 at 3:14 AlexAlex 1,4004 gold badges15 silver badges19 bronze badges 3- Which version of IE? Works fine for me in IE9. jsfiddle/m6SvE – James Montagne Commented Nov 28, 2011 at 3:17
- don't use innerHTML. Check out [this question!!][1] [1]: stackoverflow./questions/8267245/… – Vicky Commented Nov 28, 2011 at 9:39
- don't use innerHTML. Check out [this question!!][1] [1]: stackoverflow./questions/8267245/… – Vicky Commented Nov 28, 2011 at 9:39
2 Answers
Reset to default 5I think the problem is that you're naming variables with the same name as DOM elements. I seem to recall IE treating dom elements as first-class citizens, so this may be the cause of your problem.
Try:
var hourHtml = document.getElementById("hour").innerHTML;
var minHtml = document.getElementById("min").innerHTML;
var secHtml = document.getElementById("sec").innerHTML;
don't use innerHTML. Apparently its microsoft proprietary function and so not in DOM Standard...
Check out this question
本文标签:
版权声明:本文标题:javascript - Internet Explorer innerHTML "Object doesn't support this property or method" - Stack Over 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745500501a2661008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论