gpt4 book ai didi

javascript - 在可编辑内容的表行上按 ENTER 单击调用 jQuery focusout

转载 作者:行者123 更新时间:2023-11-28 05:39:35 24 4
gpt4 key购买 nike

我有一个 HTML 表格,其 contenteditable 设置为 true。

现在,当我想保存更改时,我可以单击其他位置(焦点),它将保存我的更改。

我想要“Enter”点击来执行与焦点相同的功能。

到目前为止我已经尝试过,但没有成功:

$(document).ready(function(){
$('td.editable-col').on('focusout', function() {
data = {};
data['val'] = $(this).text();
data['id'] = $(this).parent('tr').attr('data-row-id');
data['index'] = $(this).attr('col-index');
if($(this).attr('oldVal') === data['val'])
return false;

$.ajax({

type: "POST",
url: "server.php",
cache:false,
data: data,
dataType: "json",
success: function(response)
{
//$("#loading").hide();
if(response.status) {
$("#msg").removeClass('alert-danger');
$("#msg").addClass('alert-success').html(response.msg);
} else {
$("#msg").removeClass('alert-success');
$("#msg").addClass('alert-danger').html(response.msg);
}
}
});
});
});

//这是 ENTER KEY 应该调用焦点的地方

$('td.editable-col').on("keydown",function(e){
var key = e.keyCode || e.charCode; // ie||others
if(key == 13) // if enter key is pressed
$(this).blur(); // lose focus
});

最佳答案

找到解决方案。

 e.preventDefault();

已解决此问题

关于javascript - 在可编辑内容的表行上按 ENTER 单击调用 jQuery focusout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39040305/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com