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
Add a ment  | 

2 Answers 2

Reset to default 5

I 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

本文标签: