$('[role="button"]').click(function() {
myMethod();
});
我知道,點擊它所謂的myMethod()
,但點擊什麼?這個jquery代碼是做什麼的?
role
是什麼意思?
這個按鈕?
<input type="button" ... />
什麼是:[role="button"]
?
$('[role="button"]').click(function() {
myMethod();
});
我知道,點擊它所謂的myMethod()
,但點擊什麼?這個jquery代碼是做什麼的?
role
是什麼意思?
這個按鈕?
<input type="button" ... />
什麼是:[role="button"]
?
這是一個attribute equals選擇器。 $('[role="button"]')
將選擇屬性爲role
設置爲button
的所有元素。
對於前:
以下所有三人將當你做$('[role="button"]')
<div role="button" ></div>
<p role="button" ></p>
<button role="button"></button>
選擇但這不會
<input type="button">
@gapple謝謝 –
選擇器正在選擇等於button
的role
屬性。
選擇與屬性的作用,其值是按鈕
$('[role="button"]') ; // It is not the button in context
//
<input role="button" ... /> // this is selected
<input type="button" ... /> // Not this
<input role="button" ... /> // this is selected
如果你想用jQuery工作,我建議你習慣文檔:HTTP:// api.jquery.com/category/selectors/ –