如何在 jQuery 中使用 focusout 切换点击事件
How do toggle click event with focusout in jQuery
我有几个文本框的表单,其中包含聚焦事件和聚焦事件。我无法触发按钮上的点击事件,因为一旦我从文本框中丢失内容,就会调用 focus out 事件。如何在 focus out 之后触发点击事件?
$(document).on("focusout", ".fn-enlargeTextarea", function(event) {
var optionNumber = ($(this).attr('id').replace('1option','')).trim();
$('#1option'+optionNumber+'_counter').remove();
$(this).removeClass('textarea-height01').addClass('textarea-height02');
});
你可以使用 event.relatedtarget
$(document).on("focusout", ".fn-enlargeTextarea", function(event) {
var optionNumber = ($(this).attr('id').replace('1option','')).trim();
$('#1option'+optionNumber+'_counter').remove();
$(this).removeClass('textarea-height01').addClass('textarea-height02');
var targetEvent = event.relatedTarget;
$(targetEvent).click();
});
我有几个文本框的表单,其中包含聚焦事件和聚焦事件。我无法触发按钮上的点击事件,因为一旦我从文本框中丢失内容,就会调用 focus out 事件。如何在 focus out 之后触发点击事件?
$(document).on("focusout", ".fn-enlargeTextarea", function(event) {
var optionNumber = ($(this).attr('id').replace('1option','')).trim();
$('#1option'+optionNumber+'_counter').remove();
$(this).removeClass('textarea-height01').addClass('textarea-height02');
});
你可以使用 event.relatedtarget
$(document).on("focusout", ".fn-enlargeTextarea", function(event) {
var optionNumber = ($(this).attr('id').replace('1option','')).trim();
$('#1option'+optionNumber+'_counter').remove();
$(this).removeClass('textarea-height01').addClass('textarea-height02');
var targetEvent = event.relatedTarget;
$(targetEvent).click();
});