我使用jQuery和form plugin一起使用,我希望在提交之前截取表單數據並進行更改。在提交之前修改表單數據
表單插件有一個名爲beforeSubmit的屬性,應該這樣做,但我似乎無法獲取我指定要運行的函數。
下面是形式的標記(某些款式細節省略):
<form id="form1">
<fieldset id="login">
<legend>Please Log In</legend>
<label for="txtLogin">Login</label>
<input id="txtLogin" type="text" />
<label for="txtPassword">Password</label>
<input id="txtPassword" type="password" />
<button type="submit" id="btnLogin">Log In</button>
</fieldset>
</form>
而這裏的JavaScript,我到目前爲止有:
$(document).ready(function() {
var options = {
method: 'post',
url: 'Login.aspx',
beforeSubmit: function(formData, form, options) {
$.each(formData, function() { log.info(this.value); });
return true;
}
};
$('form#form1').ajaxForm(options);
});
(log.info()是從Blackbird我正在使用的調試器庫)
當我點擊提交按鈕而不是POST動詞時,我指定它使用GET來代替,並且我的beforeSubmi沒有記錄任何內容t功能。似乎ajaxForm插件沒有被應用到表單中,但我不明白爲什麼。任何人都可以幫忙嗎?
缺少的名稱屬性是問題。謝謝。 – 2008-12-05 21:42:01