首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

IE8上 JS不兼容。

2012-07-30 
IE8下 JS不兼容。。。最近小弟写了个简单的验证表单插件。。。如下JScript code$.fn.extend({verify:function(_t

IE8下 JS不兼容。。。
最近小弟写了个简单的验证表单插件。。。 如下

JScript code
$.fn.extend({    verify:function(_type,_str){  //_type表示验证类型:1.字符串长度(6-20) 2.有错误时报错字符串        var _error=false;        var _length=[2,20];        var _obj=this;        var _val=this.val();        tool={            check_special_notation:function(){                var _notation="~,!,@,#,$,%,^,&,*,(,),_,+,|,\\,{,},[,],:,\",;,',<,>,.,?,/";                var all_notation=_notation.split(",");                var _i=0;                for(_i=0;_i<all_notation.length;_i++){                    if(_val.indexOf(all_notation[_i])>0){                        alert('抱歉,您输入的内容包含特殊字符,请确认后输入!!');                        _error=true;                        return false;                    };                };            },            check_length:function(){                tool.check_special_notation();                var _count=parseInt(_val.length);                if(_count < parseInt(_length[0].toString()) || _count > parseInt(_length[1].toString())){                    alert(_str);                    _error=true;                    return false;                };            },            check_mail:function(){                var _notation="~,!,#,$,%,^,&,*,(,),_,+,|,\\,{,},[,],:,\",;,',<,>,.,?,/";                var all_notation=_notation.split(",");                var _i=0;                for(_i=0;_i<all_notation.length;_i++){                    if(_val.indexOf(all_notation[_i])>0){                        alert('抱歉,您输入的内容包含特殊字符,请确认后输入!!');                        _error=true;                        return false;                    };                };                if(_val.indexOf("@")<1){                    alert(_str);                    _error=true;                    return false;                }            },        };        if(_type==1){            tool.check_length();        }else if(_type==2){            tool.check_mail();        };        return _error;    }});

HTML代码:
HTML code
<form action="reg.php" method="post" style="display:none;">    <div class="box">        <p>            <label>姓名:</label>            <input type="text" id="UserName" name="UserName">        </p>        <p>            <label>性别:</label>            <input type="text" id="Sex" name="Sex">        </p>        <p>            <label>爱好:</label>            <input type="text" id="Habit" name="Habit">        </p>        <p>            <input type="submit" value="提交" onClick="submit_check();return false;">        </p>    </div>    </form>

页面调用:
JScript code
function submit_check(){    var _error=false;    $("input").each(function(index, element) {        if($(this).verify(1,"您输入的内容不符合长度,字符长度应在2-20之间!")){                 _error=true;           };    });    if(_error==false) $(":submit").attr("onClick","").click();};

IE9 火狐 google 下都能验证。。  
IE8以下的浏览器 跳过验证。。直接跳转嘞
IE8下 写JS有哪些地方要注意的么。。。。。
有哪些地方 要注意的么


[解决办法]
JSON数据最后一条不要逗号。
check_mail:function(){
var _notation="~,!,#,$,%,^,&,*,(,),_,+,|,\\,{,},[,],:,\",;,',<,>,.,?,/";


var all_notation=_notation.split(",");
var _i=0;
for(_i=0;_i<all_notation.length;_i++){
if(_val.indexOf(all_notation[_i])>0){
alert('抱歉,您输入的内容包含特殊字符,请确认后输入!!');
_error=true;
return false;
};
};
if(_val.indexOf("@")<1){
alert(_str);
_error=true;
return false;
}
},//这个去了

热点排行