標籤:des style java os strong io for cti
書到用時方恨少,的確是這樣的,很久都在用jquery了,只是用的時候不是很多,一般用的也就那麼幾個屬性和事件。用的時候需要什麼也是在網上找。以後 還是多看看手冊,多幾點東西。。。這樣用起來的時候就沒有這麼痛苦了。今天用了is 和hidden,給大家分享下,順便自己也加深下印象。
以下內容來自手冊:
:hidden匹配所有的隱藏元素,input 元素的 type 屬性為 "hidden" 的話也會被匹配到傳回值
Array<Element>
樣本
尋找所有不可見的 tr 元素
HTML 程式碼:
<table>
<tr style="display:none"><td>Value 1</td></tr>
<tr><td>Value 2</td></tr>
</table>
jQuery 代碼:
$("tr:hidden")
結果:
[ <tr style="display:none"><td>Value 1</td></tr> ]
is(expr)用一個運算式來檢查當前選擇的元素集合,如果其中至少有一個元素符合這個給定的運算式就返回true。如果沒有元素符合,或者運算式無效,都返回‘false‘. ‘filter‘ 內部實際也是在調用這個函數,所以,filter()函數原有的規則在這裡也適用。Checks the current selection against an expression and returns true, if at least one element of the selection fits the given expression.If no element fits, or the expression is not valid, then the response will be ‘false‘. ‘filter‘ is used internally, therefore all rules that apply there apply here, as well.傳回值
Boolean
參數
expr (String) :用於篩選的運算式
樣本
由於input元素的父元素是一個表單元素,所以返回true。
HTML 程式碼:
<form><input type="checkbox" /></form>
jQuery 代碼:
$("input[type=‘checkbox‘]").parent().is("form")
結果:
true
執行個體:
JavaScript代碼
<script language="javascript" src="jquery.js"></script>
<script>
jQuery(function($){
$(".abc").click(function(){
if ($(this).next(".content").is(":hidden")) {
$(this).next(".content").fadeIn("slow");
$(this).html("收合");
$(this).addClass("closeMore");
} else {
$(this).next(".content").fadeOut("slow");
$(this).html("開啟");
$(this).addClass("closeMore");
}
})
})
</script>
XML/HTML代碼
<div>
<span class="abc">開啟</span>
<div class="content" style="display: none;">
div_1 內容
</div>
</div>
<div>
<span class="abc">開啟</span>
<div class="content" style="display: none;">
div_2 內容
</div>
</div>