2012-10-17 4 views
1
$('[role="button"]').click(function() { 
      myMethod(); 
     }); 

내가 뭔가를 클릭하면 myMethod()을 클릭한다는 것을 알고 있지만 무엇을 클릭할까요?이 jquery 코드는 무엇을합니까?

role의 의미는 무엇입니까?

이 버튼이 맞습니까?

<input type="button" ... /> 

설명 : [role="button"]?

+1

, 난 당신이 문서에 익숙해하는 것이 좋습니다 선택을 동일 : HTTP : // api.jquery.com/category/selectors/ –

답변

8

선택자는 attribute equals입니다. $('[role="button"]')rolebutton으로 설정된 모든 요소를 ​​선택합니다.

예를 들어

:
세 이하는 당신이

<div role="button" ></div> 
<p role="button" ></p> 
<button role="button"></button> 

$('[role="button"]')을 수행 할 때 선택됩니다 만,이 것 값이 속성 역할을하지

<input type="button"> 
+0

@ gapple 고맙습니다. –

1

role 속성에서 선택자가 선택하는 값은 button입니다.

3

선택기 버튼

입니다
$('[role="button"]') ; // It is not the button in context 
(210)

//

<input role="button" ... /> // this is selected 
    <input type="button" ... /> // Not this 
    <input role="button" ... /> // this is selected 
관련 문제