好的,非常直截了当的 JQuery 问题,我正在努力寻找答案:
我有一个在按钮单击时调用的 JQuery 事件:
$(document).ready(function(){
resetForms('reservation');
$('#form-reservation').submit(function(event){
event.preventDefault(); //the page will no longer refresh on form submit.
var resCheck = $(this).find('input[class="reservationid"]').val(); //now we have the reservation ID, let's perform our check.
document.cancel_res.cancel_agree.checked = false;
//document.cancel_res.cancel_agree.disabled = false;
document.cancel_res.cancel_button.disabled=true;
document.form_reservation.search_button.value="Searching...";
document.form_reservation.search_button.disabled=true;
$.ajax({
url: 'inc/searchres.php',
type: 'POST',
data: 'resid='+resCheck,
success: function(data){ //data is all the info being returned from the php file
resetForms('reservation'); //clear forms
document.form_reservation.search_button.value="Search Reservation";
document.form_reservation.search_button.disabled=false;
$('#reservation-id').val(resCheck); //add read ID back into text box
var jsonData = $.parseJSON(data);
//BLAH BLAH BLAH BLAH
}
});
});
});
该函数完美运行......但是,无论如何都可以在不使用提交事件的情况下调用此函数?我试图在调用后取出所有内容$('#form-reservation').submit(function(event){
并将其放在单独的函数中,然后从提交事件中调用该函数。然而,无论出于何种原因,这都失败了。
基本上,我希望提交事件仍然触发这个函数,但我也希望能够在其他情况下调用整个函数。提前致谢!