【问题标题】:jQuery toggle not working in IEjQuery 切换在 IE 中不起作用
【发布时间】:2012-11-01 03:20:24
【问题描述】:

我有一些 jQuery 代码在 IE 之外的所有东西上都可以正常工作。切换操作不会触发,也不会隐藏或显示页脚元素。

我尝试使用条件 if 和 else 语句来使用 hide() 和 show() 而不是切换,我还尝试将语言和 src 元素添加到脚本标签,但这些角度都不起作用。我声明了最新的文档类型,并且正在使用最新版本的 wordpress。

谁能明白为什么这在 IE 中不起作用?

<script>
$(document).ready(function() {
    $("#clickme").click(function() {
        event.preventDefault()
        $("#footer").toggle(2000);
        $('#menu, #menu2, #menu3, #menu4').hide('slow');
        $(this).html(($('#clickme').text() == 'Show') ? 'Hide' : 'Show');
        $(this).toggleClass("active");
        $(this).attr("title", ($(this).hasClass("active") ? "Show" : "Hide") + " the menu");
    });
});​
</script>

【问题讨论】:

  • 您使用的是哪个版本的 jQuery?
  • 你能在 IE 中定义“不工作”...有什么错误吗?
  • 你能试着去掉2000ms左右的撇号吗?
  • “event.preventDefault()”后缺少分号?
  • @dodgerogers747,在这种情况下分号是可选的。

标签: javascript jquery wordpress internet-explorer cross-browser


【解决方案1】:

你正在使用

$("#clickme").click(function() {
    event.preventDefault();//^ event parameter is missing, so causing error
    // ...
});

应该是

$("#clickme").click(function(event) {
    event.preventDefault(); // ^
    // ...
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-07
    • 2011-02-13
    • 2012-09-21
    相关资源
    最近更新 更多