如何在IE和Safari中使用Javascript检测按钮的ID ?

How do I detect the ID of a button using Javascript in IE and Safari?

本文关键字:检测 Javascript 按钮 ID IE Safari      更新时间:2023-09-26

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

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

In Chrome: $event.relatedTarget.id = myButton .

In FF: $event.rangeParent.id = myButton .

我正在寻找一种方法来获得IE10和Safari中的按钮id。我怎么做呢?

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

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