jQuery.validate.js和asp.net母版页 [英] jQuery.validate.js and asp.net master pages
问题描述
我有jQuery的各种文件,最近我需要更改主页项目。这引起了各种jaavscript包括停止工作。计算器是暗示伟大的想法,以解决关于由ID选择获取问题。
I have jQuery in various files, and recently I have needed to change items in the master page. This has caused various jaavscript includes to stop working. Stackoverflow are suggesting great ideas to solve the issue regarding the get by ID selector.
$("#ctl00_ContentMainPane_eliteUser").html
不过我在这里我们使用jquery.validate.js验证表单控件的一个问题,所以code像这样的外部的JS文件
$(document).ready(function(){
$("#aspnetForm").validate({
rules:
{
ctl00$ContentMainPane$txtFirstName:
{
required:true,
CheckAlfaNumeric:true
},
ctl00$ContentMainPane$ctl00$ucRFI$txtComments:
{
required:true
}
},
messages:
{
ctl00$ContentMainPane$txtFirstName:
{
required:" Please enter first name"
},
ctl00$ContentMainPane$ctl00$ucRFI$txtComments:
{
required:" Please enter comments."
}
}
});
$("#" + GetPlaceholder() + "txtFirstName").blur(function(){
$("#" + GetPlaceholder() + "txtFirstName").valid();
});
jQuery.validator.addMethod("CheckAlfaNumeric", function(value, element) {
return this.optional(element) || /^[A-Za-z\ ]+$/i.test(value);
}, " Please enter alphabet.");
});
不知道如何prevent属性nameing问题,如果名称发生改变,由于母版页正在修改?
Any idea how to prevent the nameing issue of attributes if the name happens to change due to the master page being amended?
推荐答案
等待.NET 4.0,它允许您指定的ID究竟应该如何构造;)
Wait for .NET 4.0, which allows you to specify exactly how the ID's should be constructed ;)
严重:可以AFAIK手动创建规则,做这样的事情(一个JS对象,不过是一种性质的阵):
Seriously: you can AFAIK create your rules manually, doing something like (a JS object is nothing but an "array" of properties):
var myRules = new Object();
myRules[GetPlaceholder() + "txtFirstName"] = { required:true, CheckAlfaNumeric:true };
var myMessages = new Object();
myMessages[GetPlaceholder() + "txtFirstName"] = { required:"Please enter first name" };
$("#aspnetForm").validate({ rules: myRules, messages: myMessages });
这篇关于jQuery.validate.js和asp.net母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!