【问题标题】:How to get event.target/event.currentTarget for HTML-5 canvas for click handler如何为点击处理程序获取 HTML-5 画布的 event.target/event.currentTarget
【发布时间】:2015-06-16 02:19:48
【问题描述】:

我希望每个人都做得很好。

我属于 Actionscript 背景,刚开始使用 Flash CC HTML-5 画布。如何在 Flash CC for HTML-5 画布中获取 event.targetevent.currentTarget 以进行点击事件。

就像我们过去在 AS 3.0 中所做的那样:

btn.addEventListener(MouseEvent.CLICK , go);
function go(evt:MouseEvent) {
    trace(" evt - "+evt.currentTarget); // It will let us know the clicked target
}

对于 HTML-5

btn.addEventListener('click' , go.bind(this));
function go(evt){
   console.log(" evt - "+evt.????t); // what is the correct syntax here?
}

谢谢,

【问题讨论】:

    标签: javascript events actionscript html5-canvas


    【解决方案1】:

    您可以使用evt.target

    另请参阅下面的其他可能性:

    document.querySelector("div").addEventListener("click", function(e) {console.log(e);});
    <div>F12, then click here</div>

    【讨论】:

    • 感谢肯的快速回复。但是“evt. originalTarget”不起作用,它给出了未定义的。只有“evt.target”在工作。
    • @VarunSoni 让我更新(在 FF 中工作,但我没有检查其他浏览器)
    • 我在 Mac 上工作,它在 Safari、Chrome 和 FF 上工作。还在 IE 9 上工作,也在 Windows 上进行了测试。
    猜你喜欢
    • 2021-10-05
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    • 2011-12-12
    • 1970-01-01
    相关资源
    最近更新 更多