Javascript 如何以编程方式触发Focusout事件
如何仅使用JavaScript而不是jQuery以编程方式触发focusout事件 例如,在下面的代码中,由于调用了focusout()函数(或类似的事件引发函数)(focusout()不是JS函数,但这正是它的想法),因此它应该提醒“Hello,world!”Javascript 如何以编程方式触发Focusout事件,javascript,blur,programmatically,focusout,Javascript,Blur,Programmatically,Focusout,如何仅使用JavaScript而不是jQuery以编程方式触发focusout事件 例如,在下面的代码中,由于调用了focusout()函数(或类似的事件引发函数)(focusout()不是JS函数,但这正是它的想法),因此它应该提醒“Hello,world!” 函数helloWorld(){ 警惕(“你好,世界!”); } document.getElementsByTagName('form')[0]。addEventListener('focusout',函数(eventObj){ he
函数helloWorld(){
警惕(“你好,世界!”);
}
document.getElementsByTagName('form')[0]。addEventListener('focusout',函数(eventObj){
helloWorld();
});
var事件=新事件(“focusout”);
document.getElementsByTagName('form')[0].dispatchEvent(事件)代码>
您可以使用事件
构造函数来完成
函数helloWorld(){
警惕(“你好,世界!”);
}
var事件=新事件(“focusout”);
document.getElementsByTagName('form')[0].dispatchEvent(事件);
document.getElementsByTagName('form')[0]。addEventListener('focusout',函数(eventObj){
helloWorld();
});代码>
我们还可以使用“hideFocus”属性实现
Ex:
document.getElementById('linkURL').hideFocus 完美的答案,谢谢。我编辑了我的原始代码,以消除无限循环。对我来说不起作用,我通过专注于输入框来模拟它