Form submit on keyCode == “enter” (13)

血红的双手。 提交于 2019-12-05 09:36:15

Submitting the form when the Enter key is pressed is default browser behaviour. Don't mess with it. Just validate the form in the submit event.

$(targetFormID).submit(function (e) {
    var mess = error_m(targetDiv);
    if (mess.length > 0) {
        e.preventDefault();
    }
});

One other possible problem: what is targetFormID? If it's actually a string containing an element ID, you'll need

$("#" + targetFormID).submit(/* Same function as above */);

If it's a reference to the form element then $(targetFormID) is fine but your variable is misleadingly named.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!