[英]Why does `jQuery` `hide()` method not work?
我之前已經做過,但是仍然停留在這個簡單的實現中。
這是html:
<html>
<head>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="jquery-1.9.0.js"></script>
</head>
<body>
<p id='hiding'>blah</p>
<p>blahblah</p>
</body>
</html>
和javascript:
$(document).ready(function() {
$("p").click(function() {
$(this).hide();
});
});
hide()
不起作用,並且傳遞hiding
ID也不起作用。
更改腳本順序
<script type="text/javascript" src="jquery-1.9.0.js"></script>
<script type="text/javascript" src="script.js"></script>
使用.on,因為它允許對動態創建的Dom對象進行操作。
$(document).ready(function() {
$("p").on('click', function(){
$(this).hide();
});
});
那應該工作。 :)
檢查並安排腳本文件
<script type="text/javascript" src="jquery-1.9.0.js"></script>
<script type="text/javascript" src="script.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.