0

このイベントがトリガーされるたびに、選択したinvoiceLine要素のインデックスをインクリメントしようとしています。私はJQueryを初めて使用し、これに非常に苦労しているので、誰かがこれを行う簡単な方法を教えてくれるかどうか疑問に思っていました。

$invoiceLine.find('input').change(function(){
    $(this).parent().parent().next().find('div input').removeAttr('disabled');
});
4

1 に答える 1

0

インデックスによって兄弟内の要素の位置を意味する場合、after()、before()、insertAfter()、insertBefore()、append()、appendTo()などの多くのjQueryメソッドを使用して要素を簡単に移動できます簡単な例を次に示します。

HTML:

<div class="invoiceLine">
    1 <input />
</div>
<div class="invoiceLine">
    2 <input />
</div>
<div class="invoiceLine">
    3 <input />
</div>

JS:

$('.invoiceLine').find('input').change(function() {
    var line = $(this).closest('.invoiceLine'); // find enclosing invoiceLine
    var next = line.next(); // find next invoiceLine
    if (next.length) // check that current line is not last
        line.insertAfter(next); // insert current line after the next one
});​​​​​​​​​​​​​​

フィドル: http: //jsfiddle.net/antishok/DteuU/

于 2012-12-08T06:35:10.410 に答える