jQuery hide show div在Internet Explorer中不起作用 [英] jQuery hide show div doesn't work in Internet Explorer

查看:118
本文介绍了jQuery hide show div在Internet Explorer中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击 togglediv 时, commentdiv 必须可见或隐藏。以下代码在Firefox上运行,但不在Internet Explorer上运行:

When I click togglediv, commentdiv must be visible or hidden. The following code is running on Firefox but not Internet Explorer:

$(document).ready(function(){
    $("#togglediv").click(function(){ 
        if( $("#commentdiv").is(":visible") ) {
            $("#commentdiv").hide("slow");
            $("#togglediv").text("show");
        } else {
            $("#commentdiv").show("slow");
            $("#togglediv").text("hide");
        }
    });
});


推荐答案

我会尝试:

$(document).ready(function() {
  $("#togglediv").click(function() {
    // note: do this first because the :hidden test fails if you
    // do it after triggering a slow animation
    $("#togglediv").text($("#commentdiv").is(":hidden") ? "Hide" : "Sgiw");
    $("#commentdiv").toggle('slow');
  });
});

编辑:为了回应您的评论,此示例适用于我在IE7 / FF3中。 注意:我在使用慢效果时必须颠倒语句的顺序。有趣!

In response to your comment, this example works perfectly for me in IE7/FF3. Note: I did have to reverse the order of statements when using slow effects. Interesting!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <title>Test</title>
  <style type="text/css">
    #togglediv { padding: 5px; background-color: yellow; }
    #commentdiv { padding: 5px; background-color: #CCC; height: 100px; }
  </style>
</head>
<body>
  <div id="togglediv">Hide</div>
  <div id="commentdiv">thanks for answer. but i have tried this code, it was okay. i want to use toggle("slow") effect. this effect is runing firefox, but not i.e. is it a bug?</div>
  <script type="text/javascript" src="jquery-1.3.1.js"></script>
  <script type="text/javascript">
  $(function() {
    $("#togglediv").click(function() {
      $("#togglediv").text($("#commentdiv").is(":hidden") ? "Hide" : "Show");
      $("#commentdiv").toggle('slow');
    });
  });
  </script>
</body>
</html>

这篇关于jQuery hide show div在Internet Explorer中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆