繁体   English   中英

禁用Google Chrome后按钮后的POST无法使用

[英]POST after disabling button on Google Chrome doesn't work

我创建ASP .NET MVC应用程序。 在按钮上单击我调用禁用相同按钮的JavaScript。 之后(按钮具有只读禁用的属性)后期操作不会调用。 当我删除禁用按钮的JavaScript时,一切都很好。 这仅在Google Chrome中发生。

当我在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>

您需要在禁用按钮之前调用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>

尝试

function Disable() {
    $('#btn').attr('disabled', 'disabled');
    $('#btn').attr('readonly', 'readonly');

   $("form").submit();
}

编辑

change the `input` type to `button`

<form>
    <input id="btn" type="button" value="StackOverflow" />
</form>

$(function(e){
$("#btn").click(function(e){
e.preventDefault();
$(this).attr('disabled', 'disabled'); //if you can use latest version of jquery and use .prop("disabled",true)
$("form").submit();
});

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM