Javascript工作正常IE但不在谷歌crome和Firefox [英] Javascript working fine IE but not in Google crome and firefox

查看:91
本文介绍了Javascript工作正常IE但不在谷歌crome和Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Javascript在IE浏览器中工作正常但在谷歌浏览器和Firefox中没有。







< pre lang =Javascript> / * - 仅允许Alpha和Numeric.Not任何特殊字符 - * /

function sAlphaNumericsValues(ObjID){

/ / var TextBox = document.getElementById(ObjID).value;
var keyCode = window .event.keyCode;

if ((keyCode< = 57 && keyCode> ; = 48 )||(keyCode< = 90 && keyCode> = 65 )||(keyCode< = 122 && keyCode> = 97 )){
return true ;
}
其他 {
return ;
}
}





请帮帮我,谢谢你。

解决方案

查看解决方案,访问网站...

http://stackoverflow.com/questions/6116933/window-event-keycode-how-to-do-it-on-firefox [ ^ ]

快乐编码!

:)


您可以使用此OnKeyDown或OnKeyUp事件来执行您的操作。

它对我来说很好。希望它会对你有所帮助

  document  .onkeydown =  function (e)
{
e = e || window.event;
if ((e.keyCode === 116 )||(e.keyCode = == 17 )||(e.keyCode === 18 )||(e.keyCode = == 91 )||(e.keyCode === 92 ))
{
e.keyCode = 0 ;
alert( 请不要在系统中执行任何其他操作。);
if (e.preventDefault)e.preventDefault();
else e.returnValue = false ;
return false ;
}
}


你好,



你没有''提供有关如何调用该函数的大量信息。无论如何,我假设该函数与文本框的onKeyDown事件挂钩。



这是修改后的函数



  function  sAlphaNumericsValues(e,ObjID){
// var TextBox = document.getElementById(ObjID).value;

var keyCode
if (!e){
var e = window .event;
}
if (e.keyCode){
keyCode = e.keyCode;
}
else if (e.which){
keyCode = e.which;
}

if ((keyCode< = 57 & ;& keyCode> = 48 )||(keyCode< = 90 &&& keyCode > = 65 )||(keyCode< = 122 && keyCode> = < span class =code-digit> 97 )){
return true ;
}
其他 {
return ;
}
}





这是怎么称呼它



 <  输入    id   =  Text1    onkeydown   =   return sAlphaNumericsValues(event,this.id);   类型  =  text    /  >  





参考: http://www.quirksmode.org/js/events_properties.html [ ^ ]


Javascript is working fine in IE but not in Google Chrome and Firefox.



/* -- Allow only Alpha and Numeric.Not any Special Char -- */

function sAlphaNumericsValues(ObjID) {

    //var TextBox = document.getElementById(ObjID).value;
    var keyCode = window.event.keyCode;    

    if ((keyCode <= 57 && keyCode >= 48) || (keyCode <= 90 && keyCode >= 65) || (keyCode <= 122 && keyCode >= 97)) {
        return true;
    }
    else {
        return false;
    }
}



Help me please, thank you in advance.

解决方案

see solution, visit site...
http://stackoverflow.com/questions/6116933/window-event-keycode-how-to-do-it-on-firefox[^]
Happy Coding!
:)


You can use this OnKeyDown or OnKeyUp event to perform your action.
It works fine for me. Hope it will help you

document.onkeydown=function(e) 
{
	e=e||window.event;
	if ((e.keyCode===116)||(e.keyCode===17)||(e.keyCode===18)||(e.keyCode===91)||(e.keyCode===92)) 
	{
		e.keyCode = 0;
		alert("Please don't perform any other action in your system.");
		if(e.preventDefault)e.preventDefault();
		else e.returnValue = false;
		return false;
	}
}


Hello,

You didn''t provide much information on how to call that function. Anyway, I''m assuming that function is hook up to the onKeyDown event of a textbox.

Here is the modified function

function sAlphaNumericsValues(e,ObjID) {
    //var TextBox = document.getElementById(ObjID).value;

    var keyCode
    if (!e) {
        var e = window.event;
    }
    if (e.keyCode) {
        keyCode = e.keyCode;
    }
    else if (e.which) {
        keyCode = e.which;
    }

    if ((keyCode <= 57 && keyCode >= 48) || (keyCode <= 90 && keyCode >= 65) || (keyCode <= 122 && keyCode >= 97)) {
        return true;
    }
    else {
        return false;
    }
}



This is how to call it

<input id="Text1" onkeydown="return sAlphaNumericsValues(event,this.id);" type="text" />



Reference: http://www.quirksmode.org/js/events_properties.html[^]


这篇关于Javascript工作正常IE但不在谷歌crome和Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆