MVC Validation, Form Submit, Cursor Waiting Issue

2019-08-12 12:37发布

问题:

I have a form, when submitted, will turn the cursor: waiting. However if the MVC validation gives an error message because the property is required, the cursor does not turn back. How can I handle this? Here is how I am handling it now. I searched the forums, but nothing is working. Thank you.

$("form").submit(function () {
   //if MVC validation fails do not do this
    $("*").css("cursor", "wait");
});

jQuery(window).load( function () {
    //called after the load is finished.
    $("*").css("cursor", "auto");
});

回答1:

You should check whether the form is valid then you can turn the cursor.

$(function () {
    $("form").submit(function () {
        if ($(this).valid()) {
           $("*").css("cursor", "wait");
        }
    });
});