gpt4 book ai didi

jquery - .show() 不显示!

转载 作者:行者123 更新时间:2023-12-01 06:40:25 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com