好了,非常簡單的JQuery的問題,我在努力尋找一個答案:從代碼中的其他地方調用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){
調用之後取出所有內容,並將它放在一個單獨的函數中,然後從提交事件中調用該函數。但是,無論出於何種原因,這都失敗了。
基本上,我希望submit事件仍然會觸發這個函數,但我也希望能夠在其他情況下調用整個函數。提前致謝!
如果您在Firefox中開發這個功能,我強烈建議您安裝Firebug(http://getfirebug.com/),它會讓您更好地瞭解JavaScript失敗的原因。 – 2012-04-27 21:32:17