判断是否是IE;自定义onkeyup事件

    <script>
    /*onkeyup和onchange事件在IE下冲突,在此做区分*/
       if (!!window.ActiveXObject || "ActiveXObject" in window){
           console.log("The browser is IE!");
       }else {
           console.log("The browser is not IE!");
           //此部分是为了限制中文输入,style="ime-mode: disabled" 在非IE下不起作用
           var x = document.getElementById("recipients");
           x.onkeyup = function(){
           //    console.log(x.value);
               var str = x.value;
            var strArr = new Array();
            strArr = str.split(";");
            var strNewInput = strArr[strArr.length-1];
            var temp=""; 
            for(var i=0;i<strNewInput.length;i++){
                 if(strNewInput.charCodeAt(i) > 0 && strNewInput.charCodeAt(i) < 255){
                        temp+=strNewInput.charAt(i); 
                 } 
            }
            strArr.splice(strArr.length-1,1);
            $("#recipients").val("");
            var strGet = strArr +";"+ temp;
            var strFinal = strGet.replace(/,/g, ';');
            if(strFinal.indexOf(';') == 0){
                $("#recipients").val(strFinal.substring(1));
                return strFinal.substring(1);
            }
            $("#recipients").val(strFinal);
            return strFinal;
           }
       }
    </script> 

 

posted @ 2017-09-12 01:34  Rainyn  阅读(257)  评论(0编辑  收藏  举报