我需要对动态控件使用 jquery 验证。我尝试过,但我无法实现。帮我解决这个问题。
意见:
<script type="text/javascript">
$(document).ready(function () {
var count = 0;
$("#dynamicControlForm").validate();
$("#AddControls").click(function () {
count++;
var elements = "<input type='text' id='txt" + count + "'class='rec'/><br/></br>";
$(elements).appendTo("#dynamicControlForm");
$(".rec").each(function () {
$(this).rules("add", {
required: true,
messages: {
required: "Required field"
}
});
});
});
});
</script>
<div id="DynamicControlsContainer">
<input type="button" name="CreateControl" value="AddControl" id="AddControls" />
<form action="/" method="post" id="dynamicControlForm">
<input type="submit" name="DynamicControl" id="btnDynamicSubmit" value="Submit" />
</form>
</div>