2014-01-08 104 views
-1

我想我的重命名後的文本框..重命名文本框刪除某些行後刪除行

TextBoxA1 TextBoxB1
TextBoxA2 TextBoxB2
TextBoxA3 TextBoxB3

然後我刪除TextBox2中。然後,我添加一行,我得到這個

TextBox1 TextBoxB1
TextBox3 TextBoxB3
TextBox3 TextBoxB3

我想將其重命名或因爲即時通訊使用的每個ID的PHP和一個window.opener重新命名其ID

輸出應該是這樣的

TextBoxA1 <before the name is TextBoxA1> TextBoxB1 <before the name is TextBoxB1>
TextBoxA2 <before the name is TextBoxA3> TextBoxB2 <before the name is TextBoxB3>
TextBoxA3 <newly added row> TextBoxB3 <newly added row>

這裏的的jsfiddle:http://jsfiddle.net/k3vin023/MvQ4h/5/

回答

0

在這種情況下,你應該在你刪除功能重新分配所有(或至少> i)個文本框的ID(一個或多個)。

1

要使用重新索引完成自己的目標:http://jsfiddle.net/MvQ4h/8/

基本上我做的是增加的一小段代碼,通過所有的輸入文本刪除後的文本和更新值循環:

$('input[type="text"]').each(function(i, ev) { 
    var newId = 'txt' + (i + 1); 
    $(this).attr('id', newId).val(newId); 
}); 
+0

哦,非常感謝你!它的工作現在。 :) – k3vin023

+0

如果我有2個文本框在相同的TD呢? – k3vin023

+0

它應該重新索引刪除後留下的內容。試試看看會發生什麼。 – Omnilord