如何在此代码中选择下一个input[name="BIL_Rate[]"]
选择更改?
<table class="table table-striped table-bordered">
<tbody>
<tr>
<th width="60%">Date</th>
<th width="40%">Price of the night $</th>
</tr>
<tr>
<th>
<select name="BIL_RateId[]" class="form-control">
<option value="0">Custom price</option>
<option value="3">Special</option>
</select>
</th>
<td>
<div class="form-group">
<div class="col-sm-12">
<input type="text" name="BIL_Rate[]" class="form-control" required="">
</div>
</div>
</td>
</tr>
</tbody>
</table>
我尝试了什么:
select = $('select[name="BIL_RateId[]"]');
select.find('input[name="BIL_Rate[]"]').val();
感谢。
答案 0 :(得分:1)
以下是一个可以帮助您的示例:
$('select').change(function(){
var $this=$(this).val();
$(this).closest('tr').find('[name="BIL_Rate[]"]').val($this)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-striped table-bordered">
<tbody>
<tr>
<th width="60%">Date</th>
<th width="40%">Price of the night $</th>
</tr>
<tr>
<th>
<select name="BIL_RateId[]" class="form-control">
<option value="0">Custom price</option>
<option value="3">Special</option>
</select>
</th>
<td>
<div class="form-group">
<div class="col-sm-12">
<input type="text" name="BIL_Rate[]" class="form-control" required="">
</div>
</div>
</td>
</tr>
</tbody>
</table>
答案 1 :(得分:0)
此代码段可让您专注于下一个input[name="BIL_Rate[]"]
如果您想从input[name="BIL_Rate[]"]
获取值,只需更改
$('input[name="BIL_Rate[]"]').focus();
FOR
$('input[name="BIL_Rate[]"]').val();
$(function(){
$('select[name="BIL_RateId[]"]').on('change', function(){
$('input[name="BIL_Rate[]"]').focus();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-striped table-bordered">
<tbody>
<tr>
<th width="60%">Date</th>
<th width="40%">Price of the night $</th>
</tr>
<tr>
<th>
<select name="BIL_RateId[]" class="form-control">
<option value="0">Custom price</option>
<option value="3">Special</option>
</select>
</th>
<td>
<div class="form-group">
<div class="col-sm-12">
<input type="text" name="BIL_Rate[]" class="form-control" required="">
</div>
</div>
</td>
</tr>
</tbody>
</table>