我有一个使用 jquery 和 twitter 引导程序的模态表单。我已经设置了模态,所以当这个人取消表单时,/关闭模态我清除输入字段。但是,如果该人再次激活模态并将值输入到字段中,则 dom 仍将字段值视为 null。
这是我的表单 html
<div class="modal fade in" id="forgotPassModal" data-b-view="ForgotPass" data-brite-cid="bview_1" tabindex="-1" aria-hidden="false" style="margin-top: -152.66666662693024px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Security questions:</h3>
</div>
<div class="modal-body">
<p>
Please answer the following security questions, click 'Submit', and you
will receive an email containing instructions on how to change your password.
</p>
<div class="form-horizontal">
<fieldset id="forgotPassForm">
<div class="control-group">
<label class="span3" "label_4"="">What was the last name of your third grade teacher?</label>
<div class="controls">
<input type="text" class="input-large" id="forgotPass_4">
</div>
</div>
<div class="clearfix"> </div>
<div class="control-group">
<label class="span3" "label_165"="">What is your maternal grandmother's maiden name, please provide full name?</label>
<div class="controls">
<input type="text" class="input-large" id="forgotPass_165">
</div>
</div>
<div class="clearfix"> </div>
</fieldset>
</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button class="btn btn-primary forgotPassSubmit">Submit</button>
</div>
这是我的jQuery
for (var i = 0; i < $forgotPassQuest.questionId.length; i++){
var questionId = $forgotPassQuest.questionId[i]['id'];
$('#forgotPass_' + questionId).val(null);
}
$('#forgotPassModal').modal({show:true})
$('.forgotPassSubmit').click(function() {
var questAnswered = true;
for (var i = 0; i < $forgotPassQuest.questionId.length; i++){
var questionId = $forgotPassQuest.questionId[i]['id'];
questionField = $('#forgotPass_' + questionId);
questionFieldVal = questionField.val();
if (questionFieldVal == '' || questionFieldVal == null){
questAnswered = false;
} else {}
}
if (questAnswered == true) {
submitAnswers();
} else {
alert('please complete your security questions.');
}
})
$('#forgotPassModal').on('hidden', function () {
$('#forgotPassModal').remove();
});
现在表单是动态的,可以从一个用户更改为另一个用户。关于在取消/关闭时清除表单但在用户更改值时仍然让值被识别的任何想法?