/ / jQuery hide showdivがInternetExplorerで機能しない-jquery、internet-explorer

jQuery hide show divがInternet Explorerで機能しない - jquery、Internet-explorer

私がクリックすると togglediv, commentdiv 表示または非表示にする必要があります。次のコードはFirefoxで実行されていますが、InternetExplorerでは実行されていません。

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

回答:

回答№1は5

私がしようと思います:

$(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で私にとって完璧に機能します。 注意: スローエフェクトを使用する場合は、ステートメントの順序を逆にする必要がありました。面白い!

<!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>

回答№2の6

機能があります トグル 可視性をチェックすることなく、あなたが望むことを正確に実行するjqueryで:

$("#commentdiv").toggle("slow");

答え№3の2

締めくくりがありません}

試す

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

回答№4の場合は1

面白いことに気づいたこと、そして私は上でcletusが触れたと思いますが、「show」行の順序を「text」行に切り替えると、機能し始めたようです。これについての説明はありません。舞台裏で何が起こっているのかを知ることは素晴らしいことです。


回答№5の場合は1
if(document.getElementById(ThisObj).style.display == "none")
{
document.getElementById(ThisObj).style.display = "block";
}
else
{
document.getElementById(ThisObj).style.display = "none";
}

できます:)