admin管理员组文章数量:1393302
I create ASP .NET MVC application. On button click I call JavaScript that disable same button. After that (button has property readonly disabled) post action doesn't call. When I remove JavaScript that disable buttons everything is fine. This happens only in the Google Chrome.
When I try same example in Firefox or Internet Explorer everything is fine.
<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>
I create ASP .NET MVC application. On button click I call JavaScript that disable same button. After that (button has property readonly disabled) post action doesn't call. When I remove JavaScript that disable buttons everything is fine. This happens only in the Google Chrome.
When I try same example in Firefox or Internet Explorer everything is fine.
<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>
Share
Improve this question
edited Nov 16, 2011 at 20:13
Patricia
7,8024 gold badges39 silver badges70 bronze badges
asked Nov 16, 2011 at 20:05
SilverDeveloperSilverDeveloper
1872 silver badges13 bronze badges
4
-
You should use
$('...').prop('disabled', false);
for those attributes (source) – Didier Ghys Commented Nov 16, 2011 at 20:07 - 1 What is it you're trying to do? Prevent the form being submitted twice? – nachito Commented Nov 16, 2011 at 20:09
-
2
@DidierG. OP is using
jquery 1.4.4
,prop
is available in 1.6 or higher i think – Rafay Commented Nov 16, 2011 at 20:21 - @nachito - Yes, I try prevent form being submitted twice. I also try include jQuery 1.7 and try with $('...').prop('disabled', false) but doesn't help. – SilverDeveloper Commented Nov 16, 2011 at 20:39
2 Answers
Reset to default 5You need to call form.submit() before disabling the button, and return false from your event handler.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<script src="//code.jquery./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>
try
function Disable() {
$('#btn').attr('disabled', 'disabled');
$('#btn').attr('readonly', 'readonly');
$("form").submit();
}
edit
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();
});
});
本文标签: javascriptPOST after disabling button on Google Chrome doesn39t workStack Overflow
版权声明:本文标题:javascript - POST after disabling button on Google Chrome doesn't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744618024a2615850.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论