【问题标题】:How do I detect the ID of a button using Javascript in IE and Safari?如何在 IE 和 Safari 中使用 Javascript 检测按钮的 ID?
【发布时间】:2015-05-20 16:05:04
【问题描述】:

在我的代码中,我有一个指令,它有 on-blur = blurFunc($event)

假设我点击了一个具有id = "myButton"' and is outside of the directive. I need to know which button I clicked in theblurFunc` 方法的按钮。

在 Chrome 中:$event.relatedTarget.id 等于 myButton

在 FF 中:$event.rangeParent.id 等于 myButton

我正在寻找一种在 IE10 和 Safari 中获取按钮 ID 的方法。我该怎么做?

【问题讨论】:

  • 适用于 IE10,但不适用于 Safari :( 对 Safari 有什么想法吗?
  • 当我尝试使用 setTimeout 时,ng-blur 会覆盖 ng-click 并且不会调用 click。当我将其更改为 ng-mousedown 时,不会调用 ng-blur(我想在单击按钮时更新一个值,然后在模糊上使用它)
  • 通过使用 onClick(更新标志)然后 onBlur(检查标志)解决。很奇怪,Safari 没有原生解决方案……

标签: javascript angularjs html internet-explorer safari


【解决方案1】:

尝试使用window.event.srcElement.id 来获取blur 事件中按钮的ID。例如:

$("#idtesting").blur(function(e){
    console.log("Id: " + window.event.srcElement.id);
});

【讨论】:

  • 不。 secElement 有我模糊的指令,而不是我点击的按钮。
猜你喜欢
  • 2013-09-23
  • 1970-01-01
  • 2014-11-10
  • 2015-10-23
  • 2012-04-08
  • 2022-12-24
  • 2015-03-26
相关资源
最近更新 更多