我在ajax加載的表單上對serialize()有一些問題。Ajax加載表單上的jQuery序列化()不起作用
jQuery代碼:
$(document).on("submit", this.id, function(e) {
e.preventDefault();
var frm = e.target.id;
var frmData = $("#"+frm).serialize();
console.log(frm);
console.log(frmData);
});
控制檯輸出:
- 登錄表單
- (空文本)
形式其精靈(引導):
<div class="tab-pane active" id="logintab">
<div class="well">
<form class="form-horizontal" id="loginForm">
<div class="control-group">
<label class="control-label" for="inputEmail">E-mail adres</label>
<div class="controls">
<input type="email" id="inputEmail" value="[email protected]" placeholder="E-mail adres" data-validation-email-message="Not a valid e-mail address" required>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" id="inputPassword" value="test" placeholder="Wachtwoord" data-validation-required-message="Not a valid password" required>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn submitbtn"><i class="icon-signin"></i> Inloggen</button>
</div>
</div>
</form>
</div>
</div>
'AJAX加載-form',這是否意味着你的'html'使用'ajax',然後讓將這個'html'插入到頁面中? –
爲什麼不嘗試$(e.target).serialize()來代替?或者像$(「#loginForm」)。submit(function(e){console.log($(this).serialize());}); –