我有一个使用LiveValidation扩展的Webform.我有一个条件规则,如果用户选择美国,那么州或省字段必须在州缩写列表中.
我的问题是,如果用户选择美国,然后返回并更改他们的答案,则应删除验证规则,以便他们可以输入任何旧的文本字符串.我检查了我的语法四倍,函数返回一个liveValidation对象而不是一个错误对象但是规则没有删除.任何建议将不胜感激.
这是脚本:
if($('#edit-submitted-state-or-province').length){
var field12 = new LiveValidation('edit-submitted-state-or-province', { validMessage: " ", onlyOnBlur: true });
field12.add( Validate.Presence, { failureMessage: "Please enter your state or province." } );
}
$('#edit-submitted-country').change(function() {
var stateList = new Array("","AK"..."WY");
if($("#edit-submitted-country").val() == "United States"){
field12.add( Validate.Inclusion, {within: stateList, failureMessage: "Please enter a valid 2-letter state abbreviation."});
}
else{
field12.remove( Validate.Inclusion, {within: stateList, failureMessage: "Please enter a valid 2-letter state abbreviation."});
}
});
Run Code Online (Sandbox Code Playgroud) 我正在使用这个蒙面输入插件,我想检查字段是否为空.以下是我尝试过但它似乎不起作用:
HTML
<input type="text" name="phone" id="phoneid" />
Run Code Online (Sandbox Code Playgroud)
Le JavaScript:
$("#phoneid").mask("999-999-9999");
Run Code Online (Sandbox Code Playgroud)
此代码不起作用
$("#phoneid").keyup(function(){
if($("#phoneid").val().length == 0){
alert(111);
}
});
Run Code Online (Sandbox Code Playgroud)