我需要添加一个值(如果窗体正在加载时进入函数)和一个顺序id(例如id =“textbox_1” - id =“textbox_2”等。 )添加到jquery添加行中的文本框。当添加行时,jQuery将id和值添加到文本框中
要添加id,它将作为每次调用该函数时的示例,它会增加一个文本框的id结尾(例如id =“textbox1”,next id =“textbox2”等)。 ..)。
此外,请注意,第一行没有ID,我该如何解决这个问题?
添加值到文本框,这将需要,text1的进入类= TextBox1的
我现在已经是该代码。
感谢大家。
<html>
<head>
<script type="text/javascript">
function createNewRow (text1,text2){
$('#tblOtherParties > tbody').append('<tr><td>
<input type="text" class="title1" value=""/>
</td><td>
<input type="text" class="title2" value=""/>
</td><td>
<input type="button" class="btnDeleteOther" value="X"/>
</td></tr>');
}
$(document).ready(function(){
$(".btnDeleteOther").live("click", function(){
$(this).closest('tr').not(':only-child').remove();
});
$('#btnAddOther').click(function(){
createNewRow('hello','you');
});
});
</script>
</head>
<body>
<table style="float:left" id="tblOtherParties">
<thead>
<tr>
<th>Title1</th>
<th>Title2</th>
<th>
<input type="button" id="btnAddOther" value="Add"/>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" class="title1"/>
</td>
<td>
<input type="text" class="title2"/>
</td>
<td>
<input type="button" class="btnDeleteOther" value="X"/>
</td>
</tr>
</tbody>
</table>
</body>
</html>
只要行被删除,您还需要递减计数器。 – Sorpigal 2010-03-05 17:02:09
@Sorpigal:它的奇怪。如果我有10行和删除行号5,我的柜台现在在9,但我已经有行号9 ... – 2010-03-05 17:05:46
不一定,这可能实际上破坏的东西。如果他添加了三行制作计数器5,但是删除了第一行或第二行,递减计数器会使它变为3.但是3和4仍然存在(从原始第三行开始)。 – Seaux 2010-03-05 17:07:57