jquery - .show() 不显示!

标签 jquery

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(document).ready({
$('#sh').click(function(){
$('#container').show();

});
});
</script>
<style type="text/css">
#container {
width:350px;
height:350px;
border:1px solid #000000;
display:none;
}

</style>
</head>
<body>
<div id="container">
<p>paragraph 1</p>
</div>

<div>
<a href="#" id="sh">show</a>

</div>
</body>
</html>

点击链接根本不会触发.show()! 我究竟做错了什么?? 更新:我尝试了 $(document).ready({... 它没有帮助!

最佳答案

需要记住的一些事情,仅在文档加载完成后加载脚本:

$(function(){
  /* Scripts here will run only
     after the document has loaded */
});

此外,请务必 prevent the default behavior使用链接触发操作时的链接数量:

$(function(){
  $("#sh").click(function(e){
    e.preventDefault();
    $("#container").show();
  });
});

通过这些更改,代码可以按预期工作:http://jsfiddle.net/apsje/

关于jquery - .show() 不显示!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5155533/

相关文章:

jquery - 检索 jQuery 集合元素的数据属性值

javascript - 可拖动元素上的 z-index 堆叠问题(jQuery UI)

jquery - 如何从多个ajax调用中获取数据?

javascript - 对 Textarea 的内容使用 .match()

jquery - 有没有办法强制点击溢出内容来触发点击事件

jQuery Click 无法在 iScroll 4 上运行?

jquery - 为什么 jQuery.val 在 Internet Explorer 7 (IE7) 中返回数组而不是字符串?

jquery - 选择具有相同类别更改时检查输入

javascript - jQuery EasyUI : confirmation on close window

javascript - jQuery anchor preventDefault