将 Ajax 从 onclick 更改为 onsubmit

  • 本文关键字:onsubmit onclick Ajax ajax
  • 更新时间 :
  • 英文 :


我想更改以下代码,目前代码从 ajax 表的输入框中读取数据(七个脚本 - ajax 表编辑器),然后单击保存时,它会将其添加到表中。我想要它,以便在用户按回车键时执行此操作,如何通过修改代码来做到这一点:

if(editTblRow==null && editTblCell==null){
if(fieldtype!='blob'){
$($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<input type="text" id="edit_box" class="edit_input" value="' + id + '" /><div class="cell_opts"><a href="javascript:return false;" onclick="' + "editCell('','','','','','save','','" + updatestring + "');" + '">Save</a> - <a href="javascript:return false;" onclick="' + "editCell('','','','','','cancel');" + '">Cancel</a></div>'); 
} else {
$($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<textarea id="edit_box" class="edit_input" value="' + id + '" >' + id + '</textarea> <div class="cell_opts"><a href="javascript:return false;" onclick="' + "editCell('','','','','','save','','" + updatestring + "');" + '">Save</a> - <a href="javascript:return false;" onclick="' + "editCell('','','','','','cancel');" + '">Cancel</a></div>');
}

尝试使用此 JQuery 函数。这将有助于识别是否单击了回车键。

$(document).keypress(function(e) {
   if(e.which == 13) {
     // Your code here
   }
});

最新更新