2011-11-16 9 views
3

私はASP .NET MVCアプリケーションを作成します。ボタンをクリックすると、同じボタンを無効にするJavaScriptが呼び出されます。 それ以降(ボタンにはプロパティが読み込み禁止になっています)、ポストアクションは呼び出しません。ボタンを無効にするJavaScriptを削除しても問題ありません。これはGoogle Chromeでのみ発生します。Google Chromeでボタンを無効にした後にPOSTが動作しない

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> 
+0

これらの属性([source](http://api.jquery.com/prop/))には、prop( 'disabled'、false); ' ) –

+1

あなたは何をしようとしていますか?フォームが2回提出されないようにしますか? – nachito

+2

@DidierG。 OPは 'jquery 1.4.4'を使用しています、' prop'は1.6以上で利用可能です。 – Rafay

答えて

4

を試してみてください。

<!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> 
0

は、あなたがボタンを無効にする前に)(form.submitを呼び出し、イベントハンドラからfalseを返す必要が

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(); 
}); 

}); 
+0

役に立たなかった機能無効化ボタンですが、サーバーへのPOSTは機能しません。私がこの関数を呼び出していないときは、すべてうまくいきます。 – SilverDeveloper

+0

同じデータを複数回送信しないようにしています。それで全部です。 POSTの発生時にクリックした後、送信ボタンが有効になり、神経質なユーザーがボタンを何度かクリックします。その後、私たちは複数の同じデータを持っています。クリック後にボタンが無効になっていると、POSTは20秒かかるため、すべてが正常になります。 – SilverDeveloper

+0

このソリューションは問題ありませんが、Stevenのソリューションは私にとって少し上手です。再度、感謝します。 – SilverDeveloper

関連する問題