Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquerykeyup在除Firefox之外的所有浏览器中都能工作_Jquery_Cross Browser - Fatal编程技术网

jquerykeyup在除Firefox之外的所有浏览器中都能工作

jquerykeyup在除Firefox之外的所有浏览器中都能工作,jquery,cross-browser,Jquery,Cross Browser,我有这个代码来防止人们在文本框中输入“£” jQuery(document).ready(function(){ jQuery('#cp_price').keypress(function(e){ if(e.keyCode == 163){ alert("Exclude the £ sign"); return false; } }); }); 它适用于除Firefox以外的所有浏览器。有什么原因导致这不起作用吗?使用e.charC

我有这个代码来防止人们在文本框中输入“£”

jQuery(document).ready(function(){
   jQuery('#cp_price').keypress(function(e){
     if(e.keyCode == 163){
       alert("Exclude the £ sign"); 
       return false;
     }
   });
});

它适用于除Firefox以外的所有浏览器。有什么原因导致这不起作用吗?

使用
e.charCode
e.which
代替
keyCode
。事件对象的
charCode
值引用打印的字符。在Firefox7.0.1中,
e.keyCode
等于零

您可以在现场演示中查看差异:

尝试使用

e.which 
而不是

e.keyCode
我想你需要

jQuery(document).ready(function(){
   jQuery('#cp_price').keypress(function(e){
     if((e.keyCode ? e.keyCode : e.which) == 163){
       alert("Exclude the £ sign"); 
       return false;
     }
   });
});

你确定ID(#cp#U价格)是唯一的吗?你能详细说明一下“不起作用”吗??我的直觉是e.keyCode不适用于firefox——也许可以试试jquery的e.which。此外,我会将事件处理程序绑定到.keyup而不是.keypressye抱歉,我的意思是此代码应该阻止您输入英镑符号(),但是在firefox中它不起任何作用,我可以输入英镑@是的,这绝对是独一无二的