两个同时发生的事件 [英] Two simultaneous events
问题描述
我在此页面上使用了JS代码 http://200tr.ru/app/admin/一个> 当我按下十字符号时,会发生2个事件(模糊并单击),但仅运行模糊代码.我需要对比,点击交叉代码. 我该怎么办?
I have a JS code using on this page http://200tr.ru/app/admin/ When I press the cross sign, 2 events occur (blur and click), but only blur-code runs. I need contra, click-on-cross code. How can I do this?
$(function(){clickOnLink();});
function clickOnLink(){
$("span.link").on({
click: function(){
var linkId = $(this).text().replace(/\D+/g,"");
var id = $(this).attr("id");
var idNum = $(this).attr("id").replace(/\D+/g,"");
var idType = "link_"+$(this).attr("id").replace(/\d+/g,"");
var result = "<span class='link'>Переход на link</span> <input type='text' id='"+id+"' value='"+linkId+"'> <span><span class='plus'>+</span><span class='cross'>✘</span></span>";
$(this).replaceWith(function(index, oldHTML){
return result;
});
$("input").focus();
clickOnCross();
blurOnInput();
}
});
};
function clickOnCross(){
$("span.cross").on({
click: function(){
$(this).remove();
}
});
};
function blurOnInput(){
$("input").on({
blur: function(){
$(this).prev().remove();
$(this).next().remove();
var idName = $(this).attr("id");
var idNum = $(this).attr("id").replace(/\D+/g,"");
var idType = "link_"+$(this).attr("id").replace(/\d+/g,"");
$(this).replaceWith(function(index, newHTML){
var linkId = $(this).val();
var linkIdDb = "link"+$(this).val();
$.get("handlers/send_link.php", {
id: idNum,
ans: idType,
linkid: linkIdDb }
);
var result = "<span class='link' id='"+idName+"'>Переход на link"+linkId+". <a href='#link"+linkId+"'>⇗</a></span>";
return result;
});
clickOnLink();
}
});
};
推荐答案
在调用click
事件之前,以及在您希望click
事件被触发,DOM
中不再有cross
元素.
You remove the cross on the blur
event which triggers on mousedown
, way before a click
event is invoked, and when you expect your click
event to be triggered, there is no cross
element anymore in DOM
.
如果要在十字符号的click
事件上绑定某些内容,请不要在input
字段的blur
事件上将其从DOM
中删除.
If you would like to bind something on the click
event of your cross sign, don't remove it from DOM
on the blur
event of your input
field.
这篇关于两个同时发生的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!