我已经用<tr> <td> <inputs>
动态创建了表,问题是,当我单击第一个<td>
输入并单击下一个td输入时,jquery blur事件会多次触发。即使在使用event.stopImmediatePropagation()
和event.preventDefault()
之后,我也无法阻止在模糊事件上多次触发,并且我使用设置为false的标志来防止触发,但是我不能。
还有其他解决方法吗?
for(var i=0;i< data.supplierdetails.length;i++){
var j = (Math.floor(Math.random() * 100000000) + 100000000).toString().substring(1);
supplierdetailshtml += '<tr data-id="'+j+'">';
var description = data.supplierdetails[i].description;
supplierdetailshtml+= '<td><input type="text" name="rawproductname[]" id="rawproductname" value ="'+description+'" class="form-control rawproductname" readonly="true"/></td>';
supplierdetailshtml+= '<td><input type="text" name="hsncode[]" id="hsncode" class="form-control hsncode"/></td>';
var quantity = data.supplierdetails[i].quantity;
supplierdetailshtml+= '<td><input type="text" name="rawproductquantity[]" id="rawproductquantity_'+j+'" value ="'+quantity+'" class="form-control rawproductquantity" readonly="true"/></td>';
var unitcode = data.supplierdetails[i].unitcode;
supplierdetailshtml+= '<td><input type="text" name="rawproductunitcode[]" id="rawproductunitcode" value ="'+unitcode+'" class="form-control rawproductunitcode" readonly="true"/></td>';
supplierdetailshtml+='<td><input type="text" name="rawproductrate[]" id="rawproductrate_'+j+'" value="0.00" class="form-control rawproductrate"/></td>';
supplierdetailshtml+='<td><input type="text" name="rawproductprice[]" id="rawproductprice_'+j+'" value="0.00" class="form-control rawproductprice"/></td>';
supplierdetailshtml+= '<td><input type="text" name="rawproductgst[]" id="rawproductgst_'+j+'" value="0.00" class="form-control rawproductgst"/></td></tr>';
}
$(document).on('blur','.rawproductrate',function(event){
debugger;
var tr_id = $(this).closest('tr').data('id');
//alert("Data ID"+tr_id);
var rawproductquantity = $("#rawproductquantity_"+tr_id).val();
//alert("Raw Product Quantity"+rawproductquantity);
var rawproductrate = $("#rawproductrate_"+tr_id).val();
//alert("Raw Product rate"+rawproductrate);
if (rawproductrate==0 || rawproductrate=="") {
alert("Raw Product Rate Cannot be Zero");
}
var rawproductprice = parseFloat(rawproductrate*rawproductquantity).toFixed(2);
if(isNaN(rawproductprice) || rawproductprice==""){
var rawproductprice_decimal = parseFloat(rawproductprice || 0).toFixed(2);
$("#rawproductprice_"+tr_id).val(rawproductprice_decimal);
}
$("#rawproductprice_"+tr_id).val(rawproductprice);
$('.rawproductrate').off('blur');
event.stopImmediatePropagation();
event.preventDefault();
return false;
});