Jquery 防止输入控件在单击时为空
我有一个用数据填充的Jquery 防止输入控件在单击时为空,jquery,asp.net,textbox,Jquery,Asp.net,Textbox,我有一个用数据填充的asp:Listview。单击一行时,表格的一个单元格将替换为asp:TextBox,以允许编辑所选值,并在文本框上设置焦点。到目前为止,一切顺利 当我不单击时,我可以按预期编辑该值。但是,当我再次单击输入控件时,其内容将消失 $(document).ready(function () { $('tr[id*="itemRow"]').click(function () { $clickedRow = $(this); var invN
asp:Listview
。单击一行时,表格
的一个单元格将替换为asp:TextBox
,以允许编辑所选值,并在文本框上设置焦点。到目前为止,一切顺利
当我不单击时,我可以按预期编辑该值。但是,当我再次单击输入
控件时,其内容将消失
$(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
}
});
});
});
$(文档).ready(函数(){
$('tr[id*='itemRow'])。单击(函数(){
$clickedRow=$(此项);
var invNr=$clickedRow.find('span[id$=“InvoiceNumber”]”)。text(),
纽因弗尔,
oldHtml=$clickedRow.find('span[id$=“InvoiceNumber”]').html();
$clickedRow.find('span[id$=“InvoiceNumber”]')).html(',我已将插入的asp:TextBox
替换为常规htmlinput
元素,结果相同。您可以单击最后一列中的“1”查看我看到的内容。
我觉得我忽略了文本框控件的一些内置行为,如果我忽略了,那么我为自己的知识不足道歉
在任何情况下,我想要一些关于如何防止这种情况发生的建议。
非常感谢在文本框中检测到单击时退出该功能:
if($clickedRow.find('input[id$="editInvNr"]').length > 0)
return;
和往常一样,这很简单,令人沮丧…:P非常感谢