mootools에서 이벤트 위임을 사용하고 있습니다. 클릭 한 행 번호를 알고 싶습니다. 내 솔루션은이 jsfiddle에 나와 있습니다. 현재 수행중인 것보다 나은 방법이 있습니까?Mootools는 부모로부터 요소의 자식 인덱스를 가져옵니다.
내 접근 방식은 일치 항목을 찾을 때까지 요소를 비교하는 것이 었습니다. 사용할 수있는 IndexOf 메서드가 있습니까?
는 (다음은 미래를위한 jsfiddle의 데이터입니다)
HTML :
<div id="Record_List">
<div class="Row">
<input type="submit" name="Row" value="Edit"/>
</div>
<div class="Row">
<input type="submit" name="Row" value="Edit"/>
</div>
</div>
자바 스크립트 :
window.addEvent(
'domready',
function()
{
$('Record_List').addEvent(
'click:relay(input)',
function(evt, target)
{
evt.stop();
var rowElem = target.getParent();
var rowNumber = -1;
$('Record_List').getChildren('div.Row').each(
function (el, num)
{
if (rowElem === el)
{
rowNumber = num;
}
});
// Find the position of the row and display it here:
alert('Row number: ' + rowNumber);
});
});