jQuery, prevent form submit from enter but allow form submit by button click [duplicate]

一曲冷凌霜 提交于 2019-12-02 12:10:46
neokrisys

Be careful with the e.originalEvent.explicitOriginalTarget.id approach. It only works on Gecko based browsers.

Related answer.

Would have used a comment but I don't have enough reputation :(

You can prevent form submit

$("#toteform").on('submit',function(e) {
    e.preventDefault();
});

and on click of submit button you can manually submit the form.

$("#submit").click(function() {
    $('#toteform').submit();
});

I found the solution

$("#toteform").submit(function(e) {
    if (e.originalEvent.explicitOriginalTarget.id == "submit") {
        // let the form submit
        return true;
    }
    else {
        //Prevent the submit event and remain on the screen
        e.preventDefault();
        return false;
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!