用windows.prevFocus设置新值



我已经在文档中设置了先前的焦点存储。当单击按钮时,将执行一个函数。值0作为变量从按钮传输到函数。在该函数中,新值被设置为先前聚焦的元素。但这行不通。为什么不呢?我这样做的原因是因为我有更多的按钮,它们给出不同的值,但只需要使用相同的函数:setNewValue

主脚本:

window.prevFocus = $();
// Catch any bubbling focusin events (focus does not bubble)
$(document).on('focusin', ':input', function () {
// Test: Show the previous value
$("#debug").html(prevFocus.attr("id"));
// Save the previously clicked value for later
window.prevFocus = $(this);
});

脚本按钮

$("#butSetVal0").on({ 
click: function(){
newVal = 0;
setNewValue(newVal);
}
});

set new value script:

function setNewValue(newVal){
prevFocus.val(newVal).trigger("input");
}

我已经修好了。解决方案是设置'mousedown'按钮的事件处理程序。"点击"触发器检测到两次点击。第二次单击被解释为前一个焦点元素,因此是按钮本身。

最新更新