我有asp:Listview
我填充了数据。单击一行时,table
的其中一个单元格将替换为asp:TextBox
,以允许编辑所选值,并在文本框上设置焦点。到目前为止,非常好。
当我没有点击时,我可以按预期编辑该值。但是,当我再次单击input
控件时,其内容会消失。
$(document).ready(function () {
$('tr[id*="itemRow"]').click(function () {
$clickedRow = $(this);
var invNr = $clickedRow.find('span[id$="InvoiceNumber"]').text(),
newInvNr,
oldHtml = $clickedRow.find('span[id$="InvoiceNumber"]').html();
$clickedRow.find('span[id$="InvoiceNumber"]').html('<asp:TextBox ID="editInvNr" runat="server"></asp:TextBox>');
$clickedRow.find('input[id$="editInvNr"]').val(invNr).focus().focusout(function () {
//capture new invoice nr
newInvNr = $(this).val();
//switch textbox back to span using new invoice nr
$clickedRow.find('span[id$="InvoiceNumber"]').html(newInvNr);
//check if anything changed, if so update it in the db
if (newInvNr != invNr) {
//update new value to db
}
});
});
});
在jsfiddle here中,我已使用常规html asp:TextBox
元素替换了input
的插入,结果完全相同。您可以单击最后一列中的“1”以查看我看到的内容。
我觉得我忽略了文本框控件的一些内置行为,如果我是,那么我为我缺乏知识而道歉。
无论如何,我想了解如何防止这种情况发生的一些指示。 非常感谢
答案 0 :(得分:1)
在文本框中检测到单击时退出该功能:
if($clickedRow.find('input[id$="editInvNr"]').length > 0)
return;