取消隐藏div标签使用jQuery
问题描述:
http://www.frostjedi.com/terra/scripts/demo/jquery01.html取消隐藏div标签使用jQuery
点击页面上的按钮应该取消隐藏“你好,世界!” div标签不应该吗?当我点击它时,我得到一个$("#demo").style is undefined
错误。
答
您应该使用
$('#demo').show(); // to display
或
$('#demo').hide(); // to hide the div
答
$("#demo").hide()
或
$("#demo").hide()
甚至toggle()
method切换能见度:
$("#demo").toggle()
在您的示例
综合:从jQuery的documentation
实施例:
<h1 class="firstHeading" style="display: block;">Tutorials:Basic Show and Hide</h1>
<div class="examples">
<input id="hideh1" type="submit" value="Hide site tile" name="hideh1">
<input id="showh1" type="submit" value="Show site title" name="showh1">
<input id="toggleh1" type="submit" value="Toggle site title" name="toggleh1">
</div>
<script type="text/javascript">
$(document).ready(function() {
$(document).ready(function() {
$('#hideh1').click(function() {
$('div.showhide,h1').hide();
});
$('#showh1').click(function() {
$('div.showhide,h1').show();
});
$('#toggleh1').click(function() {
$('div.showhide,h1').toggle();
});
});
});
</script>
答
试试这个,最简单的一个..
<input type="button" onclick="$('#demo').toggle()" value="clicking me should unhide a div tag">
答
做
$(document).ready(function() {
$("input[type='button']").click(function() {
$("#demo").show();
});
});
或
document.getElementById("demo").style.display = "block";
答
$("#button").click(function() {
$("#div").hide();
});
$("#button").click(function() {
$("#div").show(2000);
});
答
您无法通过访问jQuery对象的属性。 (点)(它们不是JavaScript对象)
你,
$('#demo').css({'display':'none'})
或者你可以使用$('#demo').hide();
(它的快捷方式)
答
改用以下:
document.getElementById('demo').style.display = 'none'
这是你听到style
财产。该属性适用于DOM对象。 jQuery对象不是DOM对象。
当div已经可见时再次单击该按钮时会发生什么? – ThdK 2012-03-26 07:58:25
有**九个答案,但直到没有人选择。 – Jigs 2012-03-26 11:55:56