programing

가장 가까운 일치하는 요소를 찾는 쿼리

cafebook 2023. 9. 20. 20:44
반응형

가장 가까운 일치하는 요소를 찾는 쿼리

열이 있는 일련의 행이 있고 다음의 값을 선택합니다.input에 대한 이전 열에 있는 필드input키가 해제될 때 함수를 호출하는 필드(가격 입력).

시도해 본 결과:

quantity = $(this).parent().parent().children().val() ;
quantity = $(this).parent().parent().children().closest('.inputQty', this).val() ;

하지만 둘 다 작동하지 않습니다.

DOM의 예:

<div class="row">
    <div class="column"><input class="inputQty" id="quantity0" /></div>
    <div class="column"><input class="someOther" id="Other0" /></div>
    <div class="column">
        <div class="cSelect">
            <select id="currency0"><option>£</option></select>
            <input class="price" id="price0" />
        </div>
    </div>
</div>
var otherInput = $(this).closest('.row').find('.inputQty');

행 수준까지 올라갔다가 다시 아래로 내려갑니다..inputQty.

closest()부모님만 찾으시거든요, 정말 원하시는 건

$(this).closest('.row').children('.column').find('.inputQty').val();

겟 더.column의 부모this요소, 이전 형제를 가져온 다음 입력을 찾으십시오.

$(this).closest(".column").prev().find("input:first").val();

데모: http://jsfiddle.net/aWhtP/

다음을 시도해 볼 수 있습니다.

$(this).closest(".column").prev().find(".inputQty").val();

언급URL : https://stackoverflow.com/questions/11756529/jquery-find-nearest-matching-element

반응형