得到.attr('id')。长度;焦点输入的焦点

时间:2013-01-16 03:24:45

标签: javascript jquery

我正在尝试在.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++;         
});

我的问题是当我在main函数中添加它时,keypad()中的变量随主函数而变化。如果数量发生变化,我需要更改该行的价格。如何获取var leng = $(this).attr('id').length;元素.keyboard?我试过$(this).children().attr('id').length;但没有。我需要在键盘功能中分别为每一行var leng = $(this).attr('id').length;。非常感谢您的帮助!

0 个答案:

没有答案