Javascript无法在IE中运行

dil*_*ick 1 javascript css visibility

刚刚意识到我的网站无法在IE中正常工作.它在Chrome和Firefox中完美运行.在IE中问题是,由javascript影响的元素只是没有出现.我启用了Javascript,所以我不知道它与其他浏览器有什么不同.

我正在使用该toggle_visibility功能时:

function toggle_visibility_1(id) {
    var e = document.getElementById(id);
    if(e.style.display = 'inline') 
    e.style.display = 'none';
}
function toggle_visibility_2(id) {
    var e = document.getElementById(id);
    if(e.style.display = 'none') 
    e.style.display = 'inline';
}
Run Code Online (Sandbox Code Playgroud)

网站在这里:http://www.dillonbrannick.com/ 当然,除非在IE中,否则不会有明显的问题,如果在IE中它可能不是很明显,所以希望我已经描述得很好.

所以我似乎以某种方式解决了这个问题的工作原理就像它应该在这里看到的那样:http://testerwebby.tumblr.com/ 所以我不知道我做了什么,但我很快就会推出它我的网站,感谢您的帮助.

Sam*_*son 8

你正在执行任务,而不是比较:

// Sets the value of display
if ( e.style.display = 'none' )
Run Code Online (Sandbox Code Playgroud)

您应该使用==(值)或===(值和类型)来测试相等性:

// Tests the value of display
if ( e.style.display == "none" )
Run Code Online (Sandbox Code Playgroud)

如果您只想在inline和之间切换none,则以下内容会更好:

function toggle_visibility(id) {
    var e = document.getElementById(id);
    e.style.display = (e.style.display === "none") ? "inline" : "none" ;
}
Run Code Online (Sandbox Code Playgroud)

演示:http://jsbin.com/uyawop/edit#javascript,html