怎樣判斷jQuery當(dāng)前元素是隱藏還是顯示
$(this).is(":hidden"); //如果元素是隱藏的話(huà),則返回true
is挺好用的,他能夠用jQuery選擇器作為參數(shù),特別是跟jQuery里面的選擇器里面那些以冒號(hào)開(kāi)頭的篩選符配合使用,實(shí)現(xiàn)各種各樣的判斷。如: ":checked,:hidden"等等。給個(gè)例子:
<head>
<script src="jquery-1.7.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$(":button").click(function () {
if ($(this).is(":button")) {
alert("我是一個(gè)按鈕!");
}
if ($("#check1").is(":checked")) {
alert("我是被選中的");
}
if ($(".p1").is(":visible")) {
alert("p1是可見(jiàn)的");
}
})
})
</script>
</head>
<body>
<div id="div1">
<p class="p1">我是一個(gè)p</p>
<input id="check1" type="checkbox" value="" />復(fù)選框
<input type="button" value="確認(rèn)" />
</div>
</body>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家有所幫助,謝謝對(duì)腳本之家的支持!
相關(guān)文章
jquery操作checked屬性以及disabled屬性的多種方法
jQuery動(dòng)態(tài)背景圖片效果實(shí)現(xiàn)方法
jQuery 中msgTips 頂部彈窗效果實(shí)現(xiàn)代碼
IE10中flexigrid無(wú)法顯示數(shù)據(jù)的解決方法
jQuery前端框架easyui使用Dialog時(shí)bug處理
a標(biāo)簽跳轉(zhuǎn)到指定div,jquery添加和移除class屬性的實(shí)現(xiàn)方法
ExtJs動(dòng)態(tài)生成treepanel的Json格式

