需要在运行时检查文本框maxlength [英] need to check a textbox maxlength at runtime
本文介绍了需要在运行时检查文本框maxlength的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据下拉列表中选择的国家/地区生成zipcode文本框的maxlength
For(例如)US-(maxlength应小于5位数)
对于(例如)加拿大 - (maxlength应该小于8位)
我已经实现了这样但在validatorwrapper中得到错误我起诉我错过了一些脚本文件。
< script type = text / javascript >
jQuery(' #CountryID')。change(function(){
var value = jQuery(' #CountryID选项:选中')。val();
alert(值跨度>);
if ( value == AU)
alert( value );
jQuery(document).ready(function(){
// jQuery('#Form1 ').va({
规则:{
邮政编码:{
required: true ;
maxlength: 4
}
};
条消息:{
zipcode:{
required: 必需;
maxlength: 4个字符
}
}
var validator = < span class =code-keyword> new jQueryvalidatorWrapper( Form1,规则,消息);
$(' #masking')。click(function(){
if (!validator.validate())
return ;
alert( 验证成功!);
})
});
})
解决方案
(' #masking')。click(function(){
if (!validator.validate())
return ;
alert( 验证成功!);
})
});
})
不确定你在前几行尝试完成的是什么,但你可以试试这个:
(document).ready( function ()
{
i want to generate a maxlength for zipcode textbox based on a country selected in dropdown
For(e.g)U.S-(maxlength should be less than 5 digits)
For(e.g)canada-(maxlength should be less than 8 digits)
I have implemented like this but getting error in validatorwrapper i am sue i am missing some scripts file.
<script type="text/javascript">
jQuery('#CountryID').change(function () {
var value = jQuery('#CountryID option:selected').val();
alert(value);
if (value == "AU")
alert(value);
jQuery(document).ready(function () {
//jQuery('#Form1').va({
rules: {
zipcode: {
required: true;
maxlength: 4
}
};
messages: {
zipcode: {
required: "Required";
maxlength: "4 characters"
}
}
var validator = new jQueryvalidatorWrapper("Form1", rules, messages);
$('#masking').click(function () {
if (!validator.validate())
return;
alert("Validation Success!");
})
});
})
解决方案
('#masking').click(function () { if (!validator.validate()) return; alert("Validation Success!"); }) }); })
Not sure what you are trying to accomplish on your first few lines but you can try this:
(document).ready(function() {
这篇关于需要在运行时检查文本框maxlength的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文