我正在尝试将键盘添加.keyboard
到$('.keyboard').keypad();
动态插入的行。$('button[id^="product"]').click()
如果我在此之后尝试,我将插入行。它现在正在工作。
var count = 1;
$('button[id^="product"]').click(function () {
//adding row to table : WORKING FINE
var leng=$(this).attr('id').length;
var last = $(this).attr('id').substr(leng-4);
var newTr = $('<tr id="row_'+ count + last +'"></tr>');
newTr.html('<td width="29px" style="text-align:center;"><button class="del_row" id="'+ count + last +'" value="'+ item_price +'"> x </button></td><td width="144px"><input type="text" class="code" name="product'+ count +'" value="'+ prod_name +'" /></td><td width="44px" style="text-align:center;"><input class="keyboard" name="quantity'+ count +'" type="text" value="1" id="'+ quan +'"/></td><td style="width: 76px; padding-right: 10px; text-align:right;"><input type="text" class="price" name="price'+ count +'" value="'+ item_price +'" id="'+ pric +'"/></td>');
newTr.appendTo("#saletbl");
count++;
});
$('.keyboard').keypad({
var leng=$(this).attr('id').length;
var last = $(this).attr('id').substr(leng-4);
}); //not working
我试过.on
这个但不工作
$("#saletbl").on("focus", ".keyboard", function() {
$('.keyboard').keypad({
var leng=$(this).attr('id').length;
var last = $(this).attr('id').substr(leng-4);
}); //not working
});
如果我在里面尝试$('button[id^="product"]').click()
它正在工作并显示键盘
var count = 1;
$('button[id^="product"]').click(function () {
//adding row to table : WORKING FINE
$('.keyboard').keypad({
var leng=$(this).attr('id').length;
var last = $(this).attr('id').substr(leng-4);
}); // working but variable are being changed with parent
count++;
});
我的问题是当我在主函数中添加它时,其中的变量keypad()
会随着主函数而变化。如果数量发生变化,我需要更改该行的价格。我怎样才能获得var leng = $(this).attr('id').length;
元素.keyboard
?我试过$(this).children().attr('id').length;
但没有。我需要var leng = $(this).attr('id').length;
在键盘功能中分别为每一行设置。非常感谢您的帮助!