gpt4 book ai didi

Jquery查找下一个和上一个div行id

转载 作者:行者123 更新时间:2023-12-01 04:01:22 25 4
gpt4 key购买 nike

I want to find next div row id My Div Structure id

<div class="section row" id="row_1">
<div class="col-md-2"> <h6 class="fw400">Date</h6>
<label for="date_1" class="field prepend-icon">
<input type="text" id="date_1" name="date_1" class="gui-input" placeholder="Date" value="2017-02-18" readonly>
<label class="field-icon"><i class="fa fa-calendar"></i>
</label>
</label>
</div>
</div>
<div class="section row" id="row_2">
<div class="col-md-2"> <h6 class="fw400">Date</h6>
<label for="date_2" class="field prepend-icon">
<input type="text" id="date_2" name="date_2" class="gui-input" placeholder="Date" value="2017-02-18" readonly>
<label class="field-icon"><i class="fa fa-calendar"></i>
</label>
</label>
</div>
</div>

When I clicked on first row of Input box(date_1) then that time i want to get next row div id which is "row_2" . I tried but i dont know how to get this. Can you just tell me how to do this??

最佳答案

您可以使用next()prev()方法获取相邻 sibling 。稍后使用 attr() 获取 id 属性方法。

$('.row').click(function() {
console.log('Prev : ' + ($(this).prev().attr('id') || 'Not found'));
console.log('Next : ' + ($(this).next().attr('id') || 'Not found'));
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="section row" id="row_1">
<div class="col-md-2">
<h6 class="fw400">Date</h6>
<label for="date_1" class="field prepend-icon">
<input type="text" id="date_1" name="date_1" class="gui-input" placeholder="Date" value="2017-02-18" readonly>
<label class="field-icon"><i class="fa fa-calendar"></i>
</label>
</label>
</div>
</div>
<div class="section row" id="row_2">
<div class="col-md-2">
<h6 class="fw400">Date</h6>
<label for="date_2" class="field prepend-icon">
<input type="text" id="date_2" name="date_2" class="gui-input" placeholder="Date" value="2017-02-18" readonly>
<label class="field-icon"><i class="fa fa-calendar"></i>
</label>
</label>
</div>
</div>

关于Jquery查找下一个和上一个div行id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42336764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com