单击时,javascript / jquery禁用提交按钮,防止双重提交 [英] javascript/jquery disable submit button on click, prevent double submitting
问题描述
所以我有一个如下所示的提交按钮:
So I have the submit button that looks like this:
<a href="#" id="submitbutton"
onClick="document.getElementById('UploaderSWF').submit();">
<img src="../images/user/create-product.png" border="0" /></a>
当我双击它时双重明显提交,问题是
我是将信息保存在数据库中,这样我就可以在那里发布信息,
,我不想这样做。这个上传器使用flash和javscript,这里有一小块
的代码与提交的东西相关(如果它有帮助)
When I double click it double submits obviously, and the problem is that I'm saving the information in the database so I'll have dublicate information there, and I dont want that. This uploader uses flash and javscript and here is a little piece of code that is relevant to the submit thing (if it helps)
$.fn.agileUploaderSubmit = function() {
if($.browser.msie && $.browser.version == '6.0') {
window.document.agileUploaderSWF.submit();
} else {
document.getElementById('agileUploaderSWF').submit();
return false;
}
}
谢谢你们。
我感谢您的帮助。这真的是我自己无法做到的事情
,因为我对js有这么一点经验,而且我真的不知道
是怎么做的。
谢谢。
Thank you guys. I appreciate your help. This is really something I was unable to do myself because I have such a little experience with js and I dont really know how to do stuff. THANKS.
推荐答案
试试这个剪辑:
$('#your_submit_id').click(function(){
$(this).attr('disabled');
});
编辑1
哦,在你的情况下,它是一个链接,没有提交按钮......
Oh, in your case it is a link and no submit button ...
var submitted = false;
$.fn.agileUploaderSubmit = function() {
if ( false == submitted )
{
submitted = true;
if($.browser.msie && $.browser.version == '6.0') {
window.document.agileUploaderSWF.submit();
} else {
document.getElementById('agileUploaderSWF').submit();
}
}
return false;
}
编辑2
为了简化这一点,试试这个:
To simplify this, try this:
<!doctype html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
$(document).ready(function()
{
$('#yourSubmitId').click(function()
{
$(this).attr('disabled',true);
/* your submit stuff here */
return false;
});
});
//--><!]]>
</script>
</head>
<body>
<form id="yourFormId" name="yourFormId" method="post" action="#">
<input type="image" id="yourSubmitId" name="yourSubmitId" src="yourImage.png" alt="Submit" />
</form>
</body>
</html>
使用表格元素,例如< input type =image/> ;
,提交表格不是普通链接。
Use form elements, like <input type="image" />
, to submit a form not a normal link.
这样可以正常使用!
查看 jQuery.post()以提交表单。
祝你好运。
编辑3
这也适用于我:
<!doctype html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
$(document).ready(function()
{
var agileUploaderSWFsubmitted = false;
$('#submitbutton').click(function()
{
if ( false == agileUploaderSWFsubmitted )
{
agileUploaderSWFsubmitted = true;
//console.log( 'click event triggered' );
if ( $.browser.msie && $.browser.version == '6.0' )
{
window.document.agileUploaderSWF.submit();
}
else
{
document.getElementById( 'agileUploaderSWF' ).submit();
}
}
return false;
});
});
//--><!]]>
</script>
</head>
<body>
<form id="agileUploaderSWF" name="agileUploaderSWF" method="post" action="http://your.action/script.php">
<input type="text" id="agileUploaderSWF_text" name="agileUploaderSWF_text" />
</form>
<a href="#" id="submitbutton"><img src="../images/user/create-product.png" border="0" /></a>
</body>
</html>
希望这会有所帮助。
这篇关于单击时,javascript / jquery禁用提交按钮,防止双重提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!