我想找到下一个div行id 我的Div结构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>
当我点击输入框的第一行(date_1)时,那时我想获得下一行div id,即“row_2”。我试过,但我不知道如何得到这个。你能告诉我怎么做吗??
答案 0 :(得分:1)
$("#date_1").click(function(){
var id = $(this).parents().parents().next("div").attr("id");;
console.log(id);
});
答案 1 :(得分:1)
您可以使用next()
和prev()
方法获取相邻的兄弟姐妹。稍后使用attr()
方法获取id
属性。
$('.row').click(function() {
console.log('Prev : ' + ($(this).prev().attr('id') || 'Not found'));
console.log('Next : ' + ($(this).next().attr('id') || 'Not found'));
})
&#13;
<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>
&#13;
答案 2 :(得分:0)
试试这个:
$(document).ready(function(){
$('.section').click(function(){
alert($(this).next('div').attr('id'));
})
});
答案 3 :(得分:0)
使用父母和下一个。
$( "#date_1" ).focus(function() {
var id = $(this).parents().parents().next('div').prop('id');
alert(id);
});