如何使用JQuery隐藏和显示HTML元素?
问题描述:
如何使用JQuery隐藏和显示HTML元素而没有任何特殊效果?
How to I hide and show HTML elements using JQuery without any special effects?
答
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.