【发布时间】:2015-01-06 17:48:29
【问题描述】:
我正在使用引导表单向导,并希望在单击下一个按钮时验证表单。我使用 .each() 函数来验证选项卡 2 中的每个字段。
这是我要验证的字段
<div class="tab-pane" id="tab2">
<table class="table table-striped b-t b-light text-sm">
<thead>
<tr>
<th>ID</th>
<th>Quest</th>
</tr>
</thead>
<tbody>
<?php foreach ($interview as $interview) { ?>
<tr>
<td ><?php echo $interview['id']; ?></td>
<td>
<?php echo $interview['question']; ?>
</td>
<td><input type='text' name='name' class='abc' placeholder='Enter Your Answer'></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
为此,我编写了 jquery 来验证选项卡 2 上的每个字段
<script>
$(document).ready(function() {
$('#rootwizard').bootstrapWizard({onNext: function(tab, navigation, index) {
if(index==2) {
// Make sure we entered the name
$('.step2').on("click",function (){
$('.abc').each(function() {
alert('You must enter all filelds');
$('#name').focus();
});
});
}
}});
window.prettyPrint && prettyPrint()
$('.next').click( function(){
if(!$('.next').hasClass('step2'))
$('.next').addClass('step2');
});
});
</script>
当用户单击下一步按钮并且数据未保存在数据库中时,无法验证此文件
【问题讨论】:
标签: javascript php jquery twitter-bootstrap validation