【问题标题】:TypeError in Firefox but not ChromeFirefox 中的 TypeError 但 Chrome 中没有
【发布时间】:2014-03-08 15:32:36
【问题描述】:

这真的让我很困惑。在 Chrome 和 Safari 中一切运行顺利,但在 Firefox 中出现错误:

TypeError: currentButton is undefined

它将“index - currentButton”行列为错误源。我很想知道我在这里做错了什么!希望这是足够的代码来追踪问题:

document.getElementById('buttons').addEventListener('click', function(e) {

var currentButton = e.srcElement,
    index = currentButton.getAttribute('data-index');

【问题讨论】:

标签: javascript firefox


【解决方案1】:

这应该可行:

document.getElementById('buttons').addEventListener('click', function(e) {

    var currentButton = e.target || e.srcElement,
            index = currentButton.getAttribute('data-index');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 2017-12-08
    • 1970-01-01
    • 2015-09-14
    相关资源
    最近更新 更多