问题
Greetings
I am using the jquery disable on submit plug-in but I have a problem. If I disable the submit buttons they dont get passed back to the server so I cant tell which button was pressed. Is this normal? Is there anything I can do about it?
I really dont want to retool my website so I have to set a variable on form submission to tell which button was pressed.
Any ideas ?
回答1:
Here's a workaround I just found in a jQuery forum:
<script type="text/javascript">
$(document).ready(function() {
$("#sendSearch").click(function() {
$('#loadingDiv').show();
$('#sendSearch').attr("disabled", "disabled");
// these two lines are the workaround
this.form.submit();
return true;
});
});
</script>
回答2:
How to Disable the Submit Button of a Web Form
This method hides the button instead of disabling it, and programmatically inserts a disabled <button> tag to make it appear just like the submit button was disabled. Works great.
回答3:
You could do the submit via jquery and disable the button afterwards:
<input type="submit" value="do it!" onclick="$('#mainform').submit(); $(this).attr('disabled','disabled' ); $('#pleasewait').show();" />
EDIT: I forgot form.submit() is not asynchronous. You can do an ajax request instead:
$.ajax({
url: "someurl",
type:"POST",
cache: false,
dataType: "json",
success:gotIt,
async:true,
timeout:240000,
error:ajaxError,
data:$("#mainform").serialize()
});
or you could just .hide() the button, or after clicking it setting a non-functional onClick() handler and styling it to look disabled.
回答4:
Be more simple :)
var formid="#id-form-if-exists"; //Put here the id if exists
$("form"+formid).submit(function(){$("form"+formid+" input").attr("disabled",false);});
YEAH
来源:https://stackoverflow.com/questions/661752/problem-with-disabling-submit-buttons-on-form-submit