(function($){ $.common = function(){ /* * 方法的含义说明 * 用于常用选卡 * @access public * @param mixed objname 参数一的说明 切换对象的class,或id 注意 class 要加上'.' id 加上 '#' * @param mixed classname 参数二的说明 切换的class * @param mixed index 参数三的说明 切换对象的位置 * */ this.pickcard = function(objname,classname,index){ $(objname).eq(index).addclass(classname).siblings(this).removeclass(classname) } /* * 方法的含义说明 * 用于ajax获取跟网址 * @access public * @return string 返回跟网址 注意 没有 '/' * */ this.getrootpath = function(){ var strfullpath = window.document.location.href; var strpath = window.document.location.pathname; var pos = strfullpath.indexof(strpath); var prepath = strfullpath.substring(0, pos); //var postpath = strpath.substring(0, strpath.substr(1).indexof('/') + 1); return (prepath); } /* * 方法的含义说明 * 用于线条跟随 * @access public * @param mixed obj 参数一的说明 要移动到对象底下的 自身对象 用于获取距父级的left、或top * @param mixed thisname 参数二的说明 跟随的线条或。。 对类名,或id * @param mixed direction 参数三的说明 线条移动到的方向 * @param mixed speed 参数四的说明 线条移动的速度 * */ this.follow = function(obj,thisname,direction,speed){ if(direction =='left'){ var parnpx = obj.position().left; var animate = {left:parnpx}; }else if(direction =='top'){ var parnpx = obj.position().top; var animate = {top:parnpx}; }else{ var parnpx = obj.position().left; var animate = {left:parnpx}; } $(thisname).stop().animate(animate,speed) } /* * 方法的含义说明 * 用于验证表单 非法字符串 * @access public * @param mixed obj 参数一的说明 需要验证表单的对象 * @param mixed remind 参数二的说明 提示出错 两种情况 true = 弹窗 false = 标签提示 * @param mixed classname\str 参数三的说明 两种情况 一、如果提示为true,则第三参数为 提示信息 二、如果提示为false 则为 提示标签的class或id 加上 ‘.’或‘#’, * @param mixed str 参数四的说明 提示信息 */ this.illegal = function(obj){ var val = obj.value; var reg = /['"#$%&\^*》>,."<《?,。!@#¥%……’”:/;]/; if(reg.test(val)){ $('input[name="'+obj.name+'"]').attr('value','').focus(); var static = arguments[1]; if(static ===true){ str = arguments[2] ? arguments[2] : '你输入的内容有非法字符串,请重新输入'; alert(str) }else if(static ==false){ classname = arguments[2] ? arguments[2] : false; str = arguments[3] ? arguments[3] : '你输入的内容有非法字符串,请重新输入'; if(classname){ $(classname).text(str).css({display:'block'}); } } }else{ var static = arguments[1]; if(static == false){ classname = arguments[2] ? arguments[2] : false; if(classname){ $(classname).css({display:'none'}) } } } } /* * 方法的含义说明 * 用于验证表单 验证电话号码 * @access public * @param mixed obj 参数一的说明 需要验证表单的对象 * @param mixed remind 参数二的说明 提示出错 两种情况 true = 弹窗 false = 标签提示 * @param mixed classname\str 参数三的说明 两种情况 一、如果提示为true,则第三参数为 提示信息 二、如果提示为false 则为 提示标签的class或id 加上 ‘.’或‘#’, * @param mixed str 参数四的说明 提示信息 */ this.telephone = function(obj){ var val = obj.value; var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/; if(!reg.test(val)){ $('input[name="'+obj.name+'"]').attr('value','').focus(); var static = arguments[1]; if(static ===true){ str = arguments[2] ? arguments[2] : '请输入有效的手机号码'; alert(str) }else if(static ===false){ classname = arguments[2] ? arguments[2] : false; str = arguments[3] ? arguments[3] : '请输入有效的手机号码'; if(classname){ $(classname).text(str).css({display:'block'}); } } }else{ var static = arguments[1]; if(static == false){ classname = arguments[2] ? arguments[2] : false; if(classname){ $(classname).css({display:'none'}) } } } } /* * 方法的含义说明 * 用于验证表单 验证邮箱是否正确 * @access public * @param mixed obj 参数一的说明 需要验证表单的对象 * @param mixed remind 参数二的说明 提示出错 两种情况 true = 弹窗 false = 标签提示 * @param mixed classname\str 参数三的说明 两种情况 一、如果提示为true,则第三参数为 提示信息 二、如果提示为false 则为 提示标签的class或id 加上 ‘.’或‘#’, * @param mixed str 参数四的说明 提示信息 */ this.email = function(obj){ var val = obj.value; var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/; if(!reg.test(val)){ $('input[name="'+obj.name+'"]').attr('value','').focus(); var static = arguments[1]; if(static ===true){ str = arguments[2] ? arguments[2] : '邮箱格式不正确,请重新填写'; alert(str) }else if(static ===false){ classname = arguments[2] ? arguments[2] : false; str = arguments[3] ? arguments[3] : '邮箱格式不正确,请重新填写'; if(classname){ $(classname).text(str).css({display:'block'}); } } }else{ var static = arguments[1]; if(static == false){ classname = arguments[2] ? arguments[2] : false; if(classname){ $(classname).css({display:'none'}) } } } } /* * 方法的含义说明 * 用于验证表单 验证是否是数字 * @access public * @param mixed obj 参数一的说明 需要验证表单的对象 * @param mixed remind 参数二的说明 提示出错 两种情况 true = 弹窗 false = 标签提示 * @param mixed classname\str 参数三的说明 两种情况 一、如果提示为true,则第三参数为 提示信息 二、如果提示为false 则为 提示标签的class或id 加上 ‘.’或‘#’, * @param mixed str 参数四的说明 提示信息 */ this.number = function(obj){ var val = obj.value; var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/; if(!reg.test(val)){ $('input[name="'+obj.name+'"]').attr('value','').focus(); var static = arguments[1]; if(static ===true){ str = arguments[2] ? arguments[2] : '请输入整数'; alert(str) }else if(static ===false){ classname = arguments[2] ? arguments[2] : false; str = arguments[3] ? arguments[3] : '请输入整数'; if(classname){ $(classname).text(str).css({display:'block'}); } } }else{ var static = arguments[1]; if(static == false){ classname = arguments[2] ? arguments[2] : false; if(classname){ $(classname).css({display:'none'}) } } } } /* * 方法的含义说明 * 用于页面上传图片,可预览 * @access public * @param mixed node 参数一的说明 上传图片的对象 , * @return img 返回 图片 base64转码形式提取 */ this.previewimg = function preview(node){ var value = node.value; try{ var file = null; if(node.files && node.files[0] ){ file = node.files[0]; }else if(node.files && node.files.item(0)) { file = node.files.item(0); } //firefox 因安全性问题已无法直接通过input[file].value 获取完整的文件路径 try{ imgurl = file.getasdataurl(); }catch(e){ imgrul = window.url.createobjecturl(file); } }catch(e){ if (node.files && node.files[0]) { var reader = new filereader(); reader.onload = function (e) { imgurl = e.target.result; }; reader.readasdataurl(node.files[0]); } } return imgrul; } } })(jquery);