在 Google Chrome 上禁用按钮后 POST 不起作用

Sil*_*per 3 javascript asp.net-mvc jquery google-chrome

我创建了 ASP .NET MVC 应用程序。单击按钮时,我调用禁用相同按钮的 JavaScript。之后(按钮的属性只读被禁用)发布操作不会调用。当我删除禁用按钮的 JavaScript 时,一切都很好。这只发生在谷歌浏览器中。

当我在 Firefox 或 Internet Explorer 中尝试相同的示例时,一切都很好。

<script src="../../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>

<script type="text/javascript">

    jQuery(document).ready(function () {
        Enable();
    });


    function Enable() {
        $('#btn').removeAttr('disabled');
        $('#btn').removeAttr('readonly');
    }

    function Disable() {
        $('#btn').attr('disabled', 'true');
        $('#btn').attr('readonly', 'true');
    }
</script>
<h2>Example</h2>

<form>
    <input id="btn" type="submit" value="StackOverflow" onclick="Disable()" />
</form>
Run Code Online (Sandbox Code Playgroud)

Ste*_*ven 5

您需要在禁用按钮之前调用 form.submit(),并从您的事件处理程序返回 false。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">



<head>

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

<title>Untitled 1</title>

</head>



<body>

<script src="//code.jquery.com/jquery-1.4.4.min.js" type="text/javascript"></script> 



<script type="text/javascript"> 



    jQuery(document).ready(function () { 

        Enable(); 

    }); 





    function Enable() { 

        $('#btn').removeAttr('disabled'); 

        $('#btn').removeAttr('readonly'); 

    } 



    function Disable() { 

        $('#myform').submit();



        $('#btn').attr('disabled', 'true'); 

        $('#btn').attr('readonly', 'true'); 



        return false;

    } 

</script> 

<h2>Example</h2> 



<form id="myform" method="post"> 

    <input id="btn" type="submit" value="StackOverflow" onclick="return Disable()" /> 

</form> 



</body>



</html>
Run Code Online (Sandbox Code Playgroud)