1

刚刚意识到我的网站在 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';
}

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

所以我似乎以某种方式解决了这个问题,如果你愿意,它应该在这里看到:http: //testerwebby.tumblr.com/ 所以我不知道我做了什么,但我很快就会把它推广到我的网站,谢谢大家的帮助。

4

1 回答 1

8

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

// Sets the value of display
if ( e.style.display = 'none' )

您应该使用==(value) 或===(value and type) 来测试相等性:

// Tests the value of display
if ( e.style.display == "none" )

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

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

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

于 2012-05-10T07:15:18.920 回答