this.replace(/(^\s*)|(\s*$)/g, ""); // 用正则表达式去除前后空格 this.replace(/[&%_#/'/"]/g, ""); //除掉%_#的特殊字符 this.replace(/<\/?[^>]*>/g,''); //去除HTML tag document.onkeyup = keyUpFunction; //这样就可以监听键盘事件了 function keyUpFunction(e){ //调用该方法的时候需要将event传递过来,是现在 e = window.event || e; //IE FF上均可调用e.keyCode if(e.keyCode == 13){ searchKeyword(); } }
屏蔽键盘事件:
function resizeWindow(e){ var source=e||event; if(source.keyCode == 122){//这里针对的是F11键,如果要针对所有键盘,可以去掉这个判断 if(e){ //说明是火狐 e.preventDefault(); }else if(event){ //说明是IE event.keyCode=0; event.returnValue=false; } } } document.onkeydown=resizeWindow;//绑定监听键盘事件