JQuery学习之控制相关控件的隐藏

来源:互联网 发布:hash 统计海量数据 编辑:程序博客网 时间:2024/06/05 16:31

首先引用jquery库

<script type="text/javascript" src="/jquery/jquery.js"></script>

实现隐藏的多种方法:
第一种:实现当前隐藏

<html><head><script type="text/javascript" src="/jquery/jquery.js"></script><script type="text/javascript">$(document).ready(function(){  $("button").click(function(){  $(this).hide();});});</script></head><body><button type="button">Click me</button></body></html>

第二种:根据Id来隐藏

$(document).ready(function(){  $("button").click(function(){    $("#test").hide();  });});</script></head><body><h2>This is a heading</h2><p>This is a paragraph.</p><p id="test">This is another paragraph.</p><button type="button">Click me</button></body>

第三种:根据标签来隐藏

$(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 type="button">Click me</button></body>

第四种:根据样式来隐藏:

$(document).ready(function(){  $("button").click(function()  {  $(".test").hide();  });});</script></head><body><h2 class="test">This is a heading</h2><p class="test">This is a paragraph.</p><p>This is another paragraph.</p><button type="button">Click me</button></body>
原创粉丝点击