为什么自定义验证的jQuery的的document.ready不工作 [英] Why Custom Validator doesnt work in the document.ready of jQuery
问题描述
我调用一个函数trought我对.NET自定义验证:
I call a function trought my Custom validator on .NET :
<asp:CheckBox ID="chbNota" runat="server" />
<asp:CustomValidator ClientValidationFunction="RequiredPrivacy" Runat="server" ID="cvPrivacy" onservervalidate="CustomValidatorchkPrivacy_ServerValidate" > *</asp:CustomValidator>
现在,如果我声明函数到$(文件)。就绪(函数()为:
Now, If I declare the function into $(document).ready(function() as :
$(document).ready(function() {
function RequiredPrivacy(oSrc, args) {
if (!$('#<%=chbNota.ClientID%>').prop("checked")) args.IsValid = false;
}
});
在客户端的整个验证程序去实现。
the whole Validator on client side go to true.
为什么这种行为?如果我动议功能出$(文件)。就绪(函数()所有的工作完美...
Why this behaviour? If I move that function out of $(document).ready(function() all work perfectly...
推荐答案
当你定义在你的准备处理的功能,它隐藏在全局范围内。这就像只为处理函数,一个局部变量,换句话说。
When you define the function inside your "ready" handler, it's hidden from the global scope. It's like a local variable just for the handler function, in other words.
有没有必要定义意在全局可见内部的准备处理函数。如果你的真正的希望,但是,你可以这样做:
There's no need to define functions intended to be globally visible inside a "ready" handler. If you really want to, however, you could do this:
$(document).ready(function() {
window['RequiredPrivacy'] = function(oSrc, args) {
if (!$('#<%=chbNota.ClientID%>').prop("checked")) args.IsValid = false;
}
});
这篇关于为什么自定义验证的jQuery的的document.ready不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!