捕获TextArea中不允许的击键 [英] Capturing Keystrokes that are not permitted within a TextArea

查看:60
本文介绍了捕获TextArea中不允许的击键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一个功能方便我可以应用于

表格中的各种文本框,每个文本框将允许大多数字符,但我想禁止每个字符的某些

字符文本框。


因此我需要一个可以放入< text区域>的函数。每个

框的标签,类似于......


< text area onKeyPress =" BanCharacters('''',''< '',''>'',''b'','''',''我');">


这可能很容易吗?


干杯!

Has anyone a function handy that I can apply to various textboxes within a
form, each textbox will permit most characters but I want to ban certain
characters from each textbox.

Therefore I need a function that I can put into the <text area> tag of each
box, something like...

<text area onKeyPress="BanCharacters(''a'',''<'',''>'',''b'',''u'',''i'') ;">

Is this possible easily?

Cheers!

推荐答案

@sh在2005年12月20日上午6:41发表以下内容:
@sh said the following on 12/20/2005 6:41 AM:
有没有一个函数方便我可以应用于
表单中的各种文本框,每个文本框将允许大多数字符,但我想禁止每个文本框中的某些
字符。

因此我需要一个可以放入< text area>的函数。每个
框的标记,类似于......

<文本区域onKeyPress =" BanCharacters('''',''<'',''>' ',''b'','''',''我'');">
Has anyone a function handy that I can apply to various textboxes within a
form, each textbox will permit most characters but I want to ban certain
characters from each textbox.

Therefore I need a function that I can put into the <text area> tag of each
box, something like...

<text area onKeyPress="BanCharacters(''a'',''<'',''>'',''b'',''u'',''i'') ;">




< textarea onkeypress =" banCharacters(这个,''字符列表在这里'');

name =" myTextArea1">


然后banCharacters可以检查击键并与

列表。如果它在列表中,则返回false。


最好为每个textarea设置一个数组或简单对象

预定义,这样你就不会不得不担心语法或参数

列表长度。


更简单/更好的是一个数组/对象,其中包含所有

他们。这样的事情:


var myList = new Object();

myList [''myTextArea1''] = [''a''''' <'',''>'',''b'',''u'',''我'']

myList [''myTextArea2''] = ['' <'',''>'',''b'','''',''我']

等等。


函数banCharacters(textAreaRef){

//myList[textAreaRef.name]将为您提供对列表的引用。

//循环遍历该列表与按键相比。

//如果匹配则返回false

}


还有更多工作要做,但方法就在那里。写下

你最好的尝试并把它贴回这里。

-

兰迪

comp.lang .javascript常见问题解答 - http://jibbering.com/faq &新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /



<textarea onkeypress="banCharacters(this,''character list here'');
name="myTextArea1">

Then banCharacters could check the keystrokes and compare against the
list. If its in the list, return false.

Might be better to have an array or simple object for each textarea
predefined so that you don''t have to worry about syntax or arguments
list length.

Even simpler/better would be an array/object that had a list of all of
them. Something like this:

var myList = new Object();
myList[''myTextArea1''] = [''a'',''<'',''>'',''b'',''u'',''i'']
myList[''myTextArea2''] = [''<'',''>'',''b'',''u'',''i'']
and so on.

function banCharacters(textAreaRef){
//myList[textAreaRef.name] will give you a reference to the list.
//loop through that list and compare to the keypress.
//return false if it matches
}

There is more work to it than that, but the approach is there. Write
your best try at it and post it back here.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


>还有更多的工作要做,但方法就在那里。写下你的
> There is more work to it than that, but the approach is there. Write your
最好试试并发回这里。




谢谢兰迪,我会试一试; o)我必须先完成应用程序

所以我会到达那里,然后使用这样的Javascript

验证位返回并清理。


干杯,



Thanks Randy, I''ll give it a go ;o) I''ve got to finish the application
first so I''ll get there, then go back and cleanup with the Javascript
verification bits like this.

Cheers,


Randy Webb< Hi ************ @ aol.com>写道:
Randy Webb <Hi************@aol.com> wrote:
var myList = new Object();
myList [''myTextArea1''] = [''a'',''<'',' '>'',''b'','''',''我'']
myList [''myTextArea2''] = [''<'',''>' ',''b'','''',''我']
var myList = new Object();
myList[''myTextArea1''] = [''a'',''<'',''>'',''b'',''u'',''i'']
myList[''myTextArea2''] = [''<'',''>'',''b'',''u'',''i'']




这是否优于


myList [''myTextArea1''] =''a<> bui'';

myList [''myTextArea2''] =''a<> bui''; < br $>



-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。



Is that somehow superior to

myList[ ''myTextArea1'' ]=''a<>bui'';
myList[ ''myTextArea2'' ]=''a<>bui'';

?

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.


这篇关于捕获TextArea中不允许的击键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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