Firefox:从表单中过滤扩展的Ascii [英] Firefox: Filter Extended Ascii from Form

查看:53
本文介绍了Firefox:从表单中过滤扩展的Ascii的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这最终成为重复的帖子,我的抱怨。出于某种原因,

的第一篇文章从未出现过。


我已经尝试过300次这种相同能力的尝试,但似乎没有/>
在Firefox中运行。以下面的代码为例。它会阻止我从零输入到第一个文本框中的
,但是它不会阻止我从

输入扩展的ascii字符(这是最终目标)。


两项注意事项:

1)输入ALT + 0156输入o。奇怪的是,状态栏文本设置为ALT0moz2 ALT0moz2 ALT0moz2。

。当我实际输入4个字符时,只有3个ALT序列出现



2)我在没有真正小键盘的笔记本电脑上工作,所以0可能是结果

我必须按住一个特殊功能键才能启用numpad

叠加。)。因此检查altKey是否正常工作,但是尝试取消ALT事件取消ALT事件失败。


有谁知道这有什么问题,或者有一个工作示例

在FIREFOX中停止ALT按键/扩展字符?

< script type =" text / javascript">

if (document.addEventListener){

document.addEventListener(" keypress",HandleEnterKey,true);

}

else {

document.attachEvent(" onkeypress",HandleEnterKey);

}

//处理表单一部分的回车键,将其绑定到提供的

提交按钮

函数HandleEnterKey(事件){

var nav = window.Event? true:false;

if(nav){

返回NetscapeEventHandler_KeyDown(事件);

}否则{

返回MicrosoftEventHandler_KeyDown();

}

}


函数NetscapeEventHandler_KeyDown(e){

if (e.which == 48){

window.status = window.status + e.which +" moz1";

e.returnValue = false;

e.cancel = true;

e.preventDefault();

返回false;

}否则如果( e.altKey){

window.status = window.status +" ALT" + e.which +" moz2";

e.returnValue = false;

e.cancel = true;

e.stopPropagation ();

e.preventDefault();

返回false;

}

返回true;

}

< / script>

< / head>

< body>

< form action ="" id =" theForm">

< input type =" text" ID = QUOT; I1"名称= QUOT; I1" />

< / form>

解决方案

bgbauer70写道:

[。 ..]


//处理表单一部分的回车键,将其绑定到提供的
提交按钮
函数HandleEnterKey(event){
var nav = window.Event? true:false;
if(nav){
返回NetscapeEventHandler_KeyDown(事件);
} else {
返回MicrosoftEventHandler_KeyDown();
}
}




我没有解决方案,但以下可能是更好的方法来确定适当的事件模型:


函数HandleEnterKey(e){

如果(e){

返回NetscapeEventHandler_KeyDown(e);

} else if(window.event){

返回MicrosoftEventHandler_KeyDown();

}

}


如果你试图限制可以输入

文本输入的字符,你可能最好使用正则表达式来测试它的值而不是
而不是试图拦截击键。


例如,我可以通过复制输入零到文本输入和

粘贴 - ctrl + v或编辑 - > ;粘贴 - 不使用零键。


[...]


-

Rob


你好Rob,


有没有基于ascii#的正则表达式测试的方法?问题是我只想要

来过滤掉高ascii(> 127)。

" RobG" < RG *** @ iinet.net.au>在消息中写道

news:43 *********************** @ per-qv1-newsreader-01.iinet.net。 au ...

bgbauer70写道:
[...]


//处理表单的一部分的输入键,绑定它提供了
提交按钮
函数HandleEnterKey(事件){
var nav = window.Event? true:false;
if(nav){
返回NetscapeEventHandler_KeyDown(事件);
} else {
返回MicrosoftEventHandler_KeyDown();
}
}



我没有解决方案,但以下可能是确定适当的事件模型的更好方法:

函数HandleEnterKey( e){
如果(e){
返回NetscapeEventHandler_KeyDown(e);
} if if(window.event){
返回MicrosoftEventHandler_KeyDown();
}
}

如果你试图限制可以输入
文本输入的字符,你可能最好使用正则表达式来测试它值得而不是试图拦截击键。

例如,我可以通过复制粘贴输入零 -
粘贴 - ctrl + v或编辑 - >粘贴 - 不使用零键。

[...]

Rob



bgbauer70写道:

有没有办法基于ascii进行正则表达式测试#?问题是我只想要过滤掉高ascii(> 127)。




一个字符串方法:

String .charCodeAt(index)

返回十进制Unicode值,但对于大多数字符,它与AASCI相同



Mick


My appologies if this ends up being a duplicate post. For some reason the
first post never showed up.

I''ve tried about 300 iterrations of this same ability, and none of them seem
to work in Firefox. Take the following code for example. It WILL stop me
from entering zero into the first text box, but it wont stop me from
entering extended ascii characters (which is the final goal).

Two items of note:
1) Typing ALT+0156 inputs "o". And strangely enough the statusbar text gets
set to "ALT0moz2 ALT0moz2 ALT0moz2". Only 3 ALT sequences show up when I
actually type 4 characters
2)Im working on a laptop that has no true numpad, so the ''0'' may be a result
of me having to hold down a special function key in order to enable a numpad
overlay.). So the check for altKey is correctly working, but attempting to
cancel the ALT event fails.

Does anyone know what is wrong with this, or have a working example that
stops ALT keypresses / Extended chars in FIREFOX ?
<script type="text/javascript">
if(document.addEventListener){
document.addEventListener("keypress", HandleEnterKey, true);
}
else{
document.attachEvent("onkeypress", HandleEnterKey);
}
// Handle the enter key for a section of a form, binding it to the provided
submit buton
function HandleEnterKey(event) {
var nav = window.Event ? true : false;
if (nav) {
return NetscapeEventHandler_KeyDown(event);
} else {
return MicrosoftEventHandler_KeyDown();
}
}

function NetscapeEventHandler_KeyDown(e) {
if (e.which == 48) {
window.status = window.status + e.which + "moz1 ";
e.returnValue = false;
e.cancel = true;
e.preventDefault();
return false;
} else if (e.altKey) {
window.status = window.status + "ALT" + e.which + "moz2 ";
e.returnValue = false;
e.cancel = true;
e.stopPropagation();
e.preventDefault();
return false;
}
return true;
}
</script>
</head>
<body>
<form action="" id="theForm">
<input type="text" id="i1" name="i1" />
</form>

解决方案

bgbauer70 wrote:
[...]


// Handle the enter key for a section of a form, binding it to the provided
submit buton
function HandleEnterKey(event) {
var nav = window.Event ? true : false;
if (nav) {
return NetscapeEventHandler_KeyDown(event);
} else {
return MicrosoftEventHandler_KeyDown();
}
}



I don''t have a solution, but the following is possibly a better way to
determine appropriate the event model:

function HandleEnterKey( e ) {
if ( e ) {
return NetscapeEventHandler_KeyDown( e );
} else if ( window.event ) {
return MicrosoftEventHandler_KeyDown();
}
}

If you are trying to restrict the characters that can be entered into a
text input, you are probably better off to use a regular expression to
test its value rather than trying to intercept keystrokes.

For example, I can enter a zero into the text input by copying and
pasting - ctrl+v or Edit->Paste - without using the zero key.

[...]

--
Rob


Hi Rob,

Is there a way to regex test based on ascii #? The problem is I just want
to filter out high ascii ( >127 ).
"RobG" <rg***@iinet.net.au> wrote in message
news:43***********************@per-qv1-newsreader-01.iinet.net.au...

bgbauer70 wrote:
[...]


// Handle the enter key for a section of a form, binding it to the
provided
submit buton
function HandleEnterKey(event) {
var nav = window.Event ? true : false;
if (nav) {
return NetscapeEventHandler_KeyDown(event);
} else {
return MicrosoftEventHandler_KeyDown();
}
}



I don''t have a solution, but the following is possibly a better way to
determine appropriate the event model:

function HandleEnterKey( e ) {
if ( e ) {
return NetscapeEventHandler_KeyDown( e );
} else if ( window.event ) {
return MicrosoftEventHandler_KeyDown();
}
}

If you are trying to restrict the characters that can be entered into a
text input, you are probably better off to use a regular expression to
test its value rather than trying to intercept keystrokes.

For example, I can enter a zero into the text input by copying and
pasting - ctrl+v or Edit->Paste - without using the zero key.

[...]

--
Rob



bgbauer70 wrote:

Is there a way to regex test based on ascii #? The problem is I just want
to filter out high ascii ( >127 ).



A string method:
String.charCodeAt(index)
Returns the decimal Unicode value, but for most characters it''s the same
as AASCI.
Mick


这篇关于Firefox:从表单中过滤扩展的Ascii的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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