DIV CSS 佈局教程網

用 jQuery 的 hide() 隱藏頁面上指定元素
編輯:JQuery特效代碼     

本文示範如何使用 jQuery 的 hide() 方法,隱藏網頁中所有 <p> 標籤的內容。

<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").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>

以標籤選擇器 $("p") 會選到頁面上所有段落元素,呼叫 hide() 後它們會一起被隱藏,而標題等其他元素不受影響。希望本文對大家的 jQuery 開發有所幫助。

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