admin管理员组文章数量:1335361
It's so simple, but I don't know why IE isn't doing my innerHTML changes and other stuff.
function changeele2() {
document.getElementById("eleme2");
document.getElementById("workout");
document.getElementById("workoutweek");
if(workout.value == "Yes") {
eleme2.style.display = "inline-block";
workoutweek.className += " requiredField";
}
}
It called if I change the value of a Dropdown:
<select id="workout" onchange="changeele2()">
<option>No</option>
<option>Yes</option>
</select>
Neither works a Button with Text
I just can't find it out. Has anyone got an idea?
It's so simple, but I don't know why IE isn't doing my innerHTML changes and other stuff.
function changeele2() {
document.getElementById("eleme2");
document.getElementById("workout");
document.getElementById("workoutweek");
if(workout.value == "Yes") {
eleme2.style.display = "inline-block";
workoutweek.className += " requiredField";
}
}
It called if I change the value of a Dropdown:
<select id="workout" onchange="changeele2()">
<option>No</option>
<option>Yes</option>
</select>
Neither works a Button with Text
I just can't find it out. Has anyone got an idea?
Share edited Jun 11, 2014 at 9:17 Hannes Schneidermayer asked Apr 17, 2013 at 22:27 Hannes SchneidermayerHannes Schneidermayer 5,7853 gold badges32 silver badges35 bronze badges 02 Answers
Reset to default 5When you do document.getElementById("eleme2")
you have to save the result of that operation and use that for subsequent access to that element.
function changeele2() {
var eleme2 = document.getElementById("eleme2");
var workout = document.getElementById("workout");
var workoutweek = document.getElementById("workoutweek");
if (workout.value == "Yes") {
eleme2.style.display = "inline-block";
workoutweek.className += " requiredField";
}
}
There are some browsers that make a global variable by the same name as the element id so that may be why it was sometimes working, but you should not rely on that.
This script shouldn't be working at all, chrome is salvaging it by looking up the elements by ID.
You should change it like this:
function changeele2()
{
var eleme2 = document.getElementById("eleme2");
var workout = document.getElementById("workout");
var workoutweek = document.getElementById("workoutweek");
if(workout.value == "Yes") {
eleme2.style.display = "inline-block";
workoutweek.className += " requiredField";
}
}
本文标签: javascriptScript works in Chrome but not IEStack Overflow
版权声明:本文标题:javascript - Script works in Chrome but not IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742262816a2442834.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论