【问题标题】:JS works on chrome but not on firefoxJS 适用于 chrome 但不适用于 Firefox
【发布时间】:2014-03-26 01:35:18
【问题描述】:

我有这个表格可以删除一个条目,当它点击它会给出一个警告框

这是 HTML

<form class="form-inline" style="display:inline;" role="form" accept-charset="UTF-8" action="http://127.0.0.1:8000/test/1" method="POST">
    <input class="hidden" type="submit" value="Delete"></input>
    <a class="m-l-sm js-delete-confirm" data-confirm="Are you sure to delete this entry ??" href="#">
        <i class="fa fa-times fa-hover" title="" data-placement="top" data-toggle="tooltip" data-original-title="Delete"></i>
    </a>
</form>

这是JS

$(document).on('click', '.js-delete-confirm', function() {
    console.log('clicked delete');
    event.preventDefault();
    var choice = confirm(this.getAttribute('data-confirm'));
    if (choice) {
        $(this).closest('form').submit()
    }
});

这适用于 Google Chrome,但不适用于 Firefox。 知道我做错了什么吗? 提前致谢

【问题讨论】:

  • 在 Firefox 中运行此程序时遇到什么错误?哪个版本的firefox会出现错误?

标签: javascript jquery google-chrome firefox


【解决方案1】:

只是一种预感,但点击处理程序中缺少的 event 参数可能会在 Firefox 中引发错误:

// Add event parameter to anonymous click function
$(document).on('click', '.js-delete-confirm', function(event) {
    console.log('clicked delete');
    event.preventDefault();
    var choice = confirm(this.getAttribute('data-confirm'));
    if (choice) {
        $(this).closest('form').submit()
    }
});

【讨论】: