javascript - 聚焦元素时发送参数

标签 javascript dom

我像这样聚焦 DOM 中的一个元素:

element.focus();

大概这是在幕后触发焦点事件?我可以使用不同的语法来提供参数吗?

我尝试了以下方法,但没有成功。如果需要的话我可以使用 jQuery:

$('.my-selector').trigger({
  type: "focus",
  options: 'argument1',
});

处理程序使用 Angular ng-focus绑定(bind):

<input type="text" ng-focus="onFocus($event)"/>

处理函数:

function onFocus(evt) {
  // I want to be able to distinguish events via state I pass
}

最佳答案

使用 jQuery 时,您可以使用

$('selector').trigger('event',[param1, param2,...])

并捕获那些带有

的人
$('selector').on('event', function(e, param1, param2, ..){..}

(http://api.jquery.com/trigger/#trigger-event-extraParameters 中所述)

<小时/>

不幸的是,这不适用于此错误报告中记录的 focus 事件:Extra parameters are not passed when triggering focus

(注意:它适用于 1.8.3 及更低版本,如链接/相关错误报告中所述:focus event ignores additional data when triggered )

关于javascript - 聚焦元素时发送参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40425753/

相关文章:

javascript - ReactJS - 在 React 类中初始化 jquery 插件的标准方法是什么?

javascript - 任何延迟边缘动画直到可见的方法

javascript - 通过名称从同一个 `module.exports` 对象调用一个函数

javascript - Cypress : How to get returned value from custom commands ?( Cypress promise )

javascript - 注册时获取用户id

javascript - Future.resolve() 是什么意思?

javascript - 将此参数绑定(bind)到命名参数

javascript - IE中的tinyMce setcontent问题

javascript - 跨站脚本攻击,麻烦

javascript - 访问 ng-app 外部的 dom