DIV CSS 佈局教程網

用 jQuery 的 hide() 隱藏元素自身
編輯:JQuery特效代碼     

本文示範如何使用 jQuery 的 hide() 方法,讓元素在點擊後把自己隱藏起來。

<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $(this).hide();
  });
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
</body>
</html>

關鍵在 $(this):在事件回呼中,this 代表目前被點擊的元素,因此 $(this).hide() 就是把自己隱藏起來。希望本文對大家的 jQuery 開發有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved