我用的jquery校验是别人封装好的
$("#telephone1").formValidator({onfocus:"区号",onshow:"",tipid:"telephoneTip",onempty:"",empty:true})
.inputValidator({min:3,onerror:"请输入正确区号"})
.regexValidator({regexp:"^[0-9]+$",onerror:"区号格式不正确"});
$("#telephone2").formValidator({onfocus:"电话号码",onshow:"",tipid:"telephoneTip",onempty:"",empty:true})
.inputValidator({min:3,onerror:"请输入正确电话号码"})
.regexValidator({regexp:"^[0-9]+$",onerror:"电话号码格式不正确"});
html代码
<div id="phone1">
<span name="myphone">
<input name="quhao" type="text" id="telephone1" size="5" maxlength="5" />
-<input type="text" name="memberPhone" onblur="lostblur();" id="telephone2" maxlength="10" />
</span>
<span id="telephoneTip"></span>
</div>
<td>
<input type="button" value="添加" id="add" name="add">
</td>
js代码
<script type="text/javascript">
$(document).ready(function() {
$("#add").click(function() {
var num=$("span[name='myphone']").length;
if(num<3){
$("#phone1").append("<span name='myphone'><br/><input name='quhao' type='text' size='5' maxlength='5' id='telephone1'/>-<input name='memberPhone' type='text' id='telephone2' maxlength='10' onblur='javaScript:lostblur();'/> <input type='button' value='删除' name='del'/></span>");
}else if(num>=3){
$("#add").attr("disabled",true);
}
});
});
//删除电话框
$("input[name='del']").live("click",function(){
var num=$("span[name='myphone']").length;
if(num<3)
{
$("#add").attr("disabled",false);
}
$(this).parent().remove();
});
</script>
真相:
5 个解决方案
#1
把jquery校验代码放到$("#add").click(function()里面执行
#2
学习了!up up
#3
学习了,upup
#4
是用你这种方法做出来的
#5
$("#phone1").append("<span name='myphone'><br/><input name='quhao' type='text' size='4' maxlength='4' id='telephone"+m+1+"'/>-<input name='memberPhone' type='text' id='telephone2"+m+1+"' maxlength='8' onblur='javaScript:lostblur();'/> <input type='button' value='删除' name='del'/></span>");
$("#telephone"+m+1).formValidator({onfocus:"区号",oncorrect:"",onshow:"",tipid:"telephoneTip",onempty:"",empty:true})
.inputValidator({min:3,onerror:"请输入正确区号"})
.regexValidator({regexp:"^\\d{3,4}$",onerror:"区号格式不正确"});
$("#telephone2"+m+1).formValidator({onfocus:"电话号码",oncorrect:"",onshow:"",tipid:"telephoneTip",onempty:"",empty:true})
.inputValidator({min:3,onerror:"请输入正确电话号码"})
.regexValidator({regexp:"^\\d{7,8}$",onerror:"电话号码格式不正确"});
$("#telephone"+m+1).formValidator({onfocus:"区号",oncorrect:"",onshow:"",tipid:"telephoneTip",onempty:"",empty:true})
.inputValidator({min:3,onerror:"请输入正确区号"})
.regexValidator({regexp:"^\\d{3,4}$",onerror:"区号格式不正确"});
$("#telephone2"+m+1).formValidator({onfocus:"电话号码",oncorrect:"",onshow:"",tipid:"telephoneTip",onempty:"",empty:true})
.inputValidator({min:3,onerror:"请输入正确电话号码"})
.regexValidator({regexp:"^\\d{7,8}$",onerror:"电话号码格式不正确"});
#1
把jquery校验代码放到$("#add").click(function()里面执行
#2
学习了!up up
#3
学习了,upup
#4
是用你这种方法做出来的
#5
$("#phone1").append("<span name='myphone'><br/><input name='quhao' type='text' size='4' maxlength='4' id='telephone"+m+1+"'/>-<input name='memberPhone' type='text' id='telephone2"+m+1+"' maxlength='8' onblur='javaScript:lostblur();'/> <input type='button' value='删除' name='del'/></span>");
$("#telephone"+m+1).formValidator({onfocus:"区号",oncorrect:"",onshow:"",tipid:"telephoneTip",onempty:"",empty:true})
.inputValidator({min:3,onerror:"请输入正确区号"})
.regexValidator({regexp:"^\\d{3,4}$",onerror:"区号格式不正确"});
$("#telephone2"+m+1).formValidator({onfocus:"电话号码",oncorrect:"",onshow:"",tipid:"telephoneTip",onempty:"",empty:true})
.inputValidator({min:3,onerror:"请输入正确电话号码"})
.regexValidator({regexp:"^\\d{7,8}$",onerror:"电话号码格式不正确"});
$("#telephone"+m+1).formValidator({onfocus:"区号",oncorrect:"",onshow:"",tipid:"telephoneTip",onempty:"",empty:true})
.inputValidator({min:3,onerror:"请输入正确区号"})
.regexValidator({regexp:"^\\d{3,4}$",onerror:"区号格式不正确"});
$("#telephone2"+m+1).formValidator({onfocus:"电话号码",oncorrect:"",onshow:"",tipid:"telephoneTip",onempty:"",empty:true})
.inputValidator({min:3,onerror:"请输入正确电话号码"})
.regexValidator({regexp:"^\\d{7,8}$",onerror:"电话号码格式不正确"});