gpt4 book ai didi

javascript - jQuery - after()-函数触发两次

转载 作者:行者123 更新时间:2023-11-30 18:34:23 25 4
gpt4 key购买 nike

这是我的代码片段:

$.ctrl('J', function() {

$("#"+currentId).after('<div contentEditable="true">test</div>');

});

运行后,将添加 2 个带有“test”的 div,而不是 1 个。

我错过了什么?

这是 CTRL 函数:

$.ctrl = function(key, callback, args) {

var isCtrl = false;

$(document).keydown(function(e) {
if (!args) args = [];
if (e.ctrlKey) isCtrl = true;
if (e.keyCode == key.charCodeAt(0) && isCtrl) {
callback.apply(this, args);
return false;
}
}).keyup(function(e) {
if (e.ctrlKey) isCtrl = false;
});
};

提前谢谢你。

问候

编辑:

可能与此有关:

$('div[id|="edid"]').focus(function() {


$('div[id|="edid"]').removeClass('onFocus');

$(this).addClass('onFocus');

var currentId = $(this).attr('id');
});

最佳答案

我遇到过类似的问题。可能您使用的是旧的 jquery 版本?

Major Bugfix in JQuery 1.4.4 - A function bound to the document ready event will now fire once (it was firing twice).

What’s New in JQuery 1.4.4

关于javascript - jQuery - after()-函数触发两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8713082/

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