我仅在第一行中获取 id 属性值,但想在其他动态创建的行中获取属性值。单击表行输入标记时应显示请帮助我找到解决方案。
脚本:
<script>
$('document').ready(function () {
$('#add').click(function () {
var id = parseInt($('#main tbody tr:last').attr('id')) + 1;
$('#main > tbody:last').append("<tr class=\"edit_tr\" id=\"" + id + "\" ><td>" + id + "</td><td><span id=\"parti_" + id + "\" class=\"text\" ></span><input type=\"text\" class=\"editbox\" id=\"parti_input_" + id + "\" /></td><td><span id=\"qty_" + id + "\" class=\"text\"></span><input type=\"text\" class=\"editbox\" id=\"qty_input_" + id + "\" /></td><td><span id=\"amountrs_" + id + "\" class=\"text\"></span><input type=\"text\" class=\"editbox\" id=\"amountrs_input_" + id + "\" /></td><td><span id=\"amountp_" + id + "\" class=\"text\"></span><input type=\"text\" class=\"editbox\" id=\"amountp_input_" + id + "\" /></td><td></td><td></td></tr>");
});
$('#del').click(function () {
$('#main tbody tr:last').remove();
});
$(".edit_tr").click(function () {
var ID = $(this).attr('id');
$("#parti_" + ID).hide();
$("#qty_" + ID).hide();
$("#amountrs_" + ID).hide();
$("#amountp_" + ID).hide();
$("#parti_input_" + ID).show();
$("#qty_input_" + ID).show();
$("#amountrs_input_" + ID).show();
$("#amountp_input_" + ID).show();
}).change(function () {
var ID = $(this).attr('id');
var first = $("#first_input_" + ID).val();
var last = $("#last_input_" + ID).val();
var dataString = 'id=' + ID + '&firstname=' + first + '&lastname=' + last;
$("#first_" + ID).html('<img src="load.gif" />'); // Loading image
});
$(".editbox").mouseup(function () {
return false
});
// Outside click action
$(document).mouseup(function () {
$(".editbox").hide();
$(".text").show();
});
});
</script>
HTML 代码:
<tbody>
<tr class="edit_tr" id="1">
<td>1</td>
<td><span id="parti_1" class="text"></span>
<input type="text" class="editbox part" id="parti_input_1" />
</td>
<td><span id="qty_1" class="text"></span>
<input type="text" class="editbox" id="qty_input_1" />
</td>
<td><span id="amountrs_1" class="text"></span>
<input type="text" class="editbox" id="amountrs_input_1" />
</td>
<td><span id="amountp_1" class="text" /></span>
<input type="text" class="editbox" id="amountp_input_1" />
</td>
<td></td>
<td></td>
</tr>
</tbody>