簡體   English   中英

JS適用於Chrome,但不適用於Firefox

[英]JS works on chrome but not on firefox

我有這張表格刪除一個條目,當它單擊時會給一個警告框

這是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。 知道我做錯了什么嗎? 提前致謝

只是預感,但是點擊處理程序上缺少的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()
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM