【发布时间】:2012-08-01 15:27:25
【问题描述】:
JQuery 验证器插件使用“名称”,我想通过 ID 动态找到它。我的 $test 变量返回一个具有正确名称的字符串,但我不能使用字符串。
如何使用此变量替换硬编码名称 (ctl00$MainContent$ListBox1)?
代替:
<script type="text/javascript">
$(document).ready(function () {
var $test = $("#ListBox1").attr("name");
$("#form1").validate({
rules: {
ctl00$MainContent$ListBox1: {
required: true,
rangelength: [0, 4]
}
},
messages: {
ctl00$MainContent$ListBox1: {
required: "Please select a state",
rangelength: "Please select maximum 4 states"
}
},
errorLabelContainer: $("#message")
});
});
</script>
我想使用类似的东西:
$("#form1").validate({
rules: {
$test: {
required: true,
rangelength: [0, 4]
}
},
【问题讨论】:
标签: javascript jquery jquery-plugins validation object-literal