Jquery 在keyup上查找最近的输入字段并向其添加值
我想在keyup上为最近的输入字段添加一个值。但它在动态添加的字段中不起作用Jquery 在keyup上查找最近的输入字段并向其添加值,jquery,keyup,Jquery,Keyup,我想在keyup上为最近的输入字段添加一个值。但它在动态添加的字段中不起作用 $(document).on('keyup', '.rate_qar' , function() { var qar_rate = $('#conv_rate_usd').val(); var usd_rate = 10*qar_rate; $(this).parent('tr').find('input.rate_usd').val(usd_rate); }); 但它不起作用。我该怎么做?我
$(document).on('keyup', '.rate_qar' , function() {
var qar_rate = $('#conv_rate_usd').val();
var usd_rate = 10*qar_rate;
$(this).parent('tr').find('input.rate_usd').val(usd_rate);
});
但它不起作用。我该怎么做?我的HTML如下所示。请注意,html输入将动态添加
<input name="rate_qar[]" type="number" min="1" placeholder="Room rate QAR" class="form-control rate_qar">
<input name="rate_usd[]" type="number" min="1" placeholder="Room type USD" class="form-control rate_usd" >
问题可能是
tr
不是输入的父项,因此使用而不是
您好@Corner,请将您的HTML添加为well@Victor:完成。请查收
$(this).closest('tr').find('input.rate_usd').val(usd_rate);