且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用JQuery隐藏和显示HTML元素?

更新时间:2022-11-10 19:09:21

使用 hide() show() 方法:

Using the hide() and show() methods:

$("selector").hide();
$("selector").show();

其中选择器"是合适的.喜欢:

Where "selector" is whatever is appropriate. Like:

<script type="text/javascript">
$(function() {
  $("#mybutton").click(function() {
    $("#mydiv").toggle();
  });
});
</script>
<div id="mydiv">
This is some text
</div>
<input type="button" id="mybutton" value="Toggle Div">

toggle() 方法仅在隐藏时调用show(),或者在其隐藏时调用hide()不是.

The toggle() method just calls show() if hidden or hide() if its not.