【发布时间】:2017-08-21 09:36:02
【问题描述】:
这是我的 javascript 代码
<script type="text/javascript">
//function to add new row
jQuery(function() {
var counter = 1;
var nextRowId=($('#tb tr').length)-1;
//number of rows fetched from database
jQuery('a.addrow').click(function(event) {
event.preventDefault();
var newRow = jQuery('<tr><td colspan="3" class="table-active">'+nextRowId+'</td><td colspan="3" class="table-active"><input type="number" name="emp_code[' + nextRowId + ']" id="emp_code[' + nextRowId + ']" class="form-control"/><div class="error"><?php echo $genderError;?></div></td><td colspan="3" class="table-success"><input type="text" name="emp_name[' + nextRowId + ']" id="emp_name[' + nextRowId + ']" class="form-control" required/></td><td colspan="3" class="table-info"><input type="text" name="emp_mailid[' + nextRowId + ']" id="emp_mailid[' + nextRowId + ']" class="form-control" required/></td><td colspan="3" class="table-info"><select required class="form-control" id="nomination[' + nextRowId + ']" name="nomination[' + nextRowId + ']"> <option value="">Select</option><option value="Nominated">Nominated</option><option value="Invited">Invited</option><option value="Both">Both</option><option value="None">Neither nominated nor invited</option></select></td><td colspan="3"><label><input type="radio" name="attendance[' + nextRowId + ']" id="attendance[' + nextRowId + ']" value="1" required>Yes</label><label><input type="radio" name="attendance[' + nextRowId + ']" id="attendance[' + nextRowId + ']" value="0">No</label></td><td><a href="javascript:void(0);" class="remove" onclick=><span class="glyphicon glyphicon-remove"></span></a></td></tr>');
counter++;
nextRowId++;
jQuery('table.table').append(newRow);
$('#emp_code['+ nextRowId + ']').rules('add',{
required:true,
});
//Init bootstrapToggle
$('.toggleone').bootstrapToggle({
on: 'Yes',
off: 'No'
});
});
});
</script>
我想使用各种约束验证单击提交按钮时输入的所有值 `
- emp_code[]`:必需和编号 emp_name[]:必需且仅 字母 emp_mailid[]:required 和电子邮件验证 提名[]:要求出席[]:要求
我尝试了 SO 的所有解决方案,但都没有成功。我在某处错了。我希望这与 jquery 相关。有人帮我做这个
【问题讨论】:
-
试用
validator jquery插件进行验证。
标签: javascript php jquery html validation