의 반환 값 this.id
이 함수에서 함수로 다양 할 때 JQuery를 사용하여 DIV에 동적 효과를 적용하고있었습니다.this.id가 정확히 무엇입니까?
나는 다음과 같은 간단한 부모 - 자식 DIV 태그의 두 세트를 가지고 :
<DIV ID="row">
<DIV ID="c1">
<Input type="radio" name="testing" id="testing" VALUE="1">testing1
</DIV>
</DIV>
<DIV ID="row">
<DIV ID="c2">
<Input type="radio" name="testing" id="testing" VALUE="2">testing2
</DIV>
</DIV>
코드 1.
$('#row DIV').mouseover(function(){
radio_btns.each(function() {
$('#row DIV).addClass('testing'); // worked
});
});
코드 2.
$('#row DIV').mouseover(function(){
var childDivID = this.id;
radio_btns.each(function() {
$('#'+childDivID).parent('DIV').addClass('testing'); // didn't work
});
});
I 돈 왜 첫 번째 코드 만 작동 할 수 있는지 이해하지 못합니다.
및 모든 "행"DIV,
강조 표시하지만 두 번째 코드는 그렇게하지 못했습니다?
가능한 중복 :이 경우 호버를 원한다면
또 하나 개의 항목, 질문 밖에서 정말,
.hover()
및.toggleClass()
, like this를 사용 둘러싼 루프] (http://stackoverflow.com/questions/2828718/javascript-scope-problem-when-lambda-function-refers-to-a-variable-in-enc-losing-l) –"하지만 * 초를 의미합니다. * 코드가 그렇게하지 못했습니다 "? – edwin
동일한 페이지에서 동일한 ID를 가진 두 개의 요소를 가질 수 없습니다. – edwin