fireEvent [英] fireEvent

查看:68
本文介绍了fireEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


任何人都知道如何使用fireEvent来模拟textarea中的shit + keypress?


谢谢,


-

,_,

(O,O)

()

---" - " -alex

Hi all,

Anyone knows how to use fireEvent to simulate a shit+keypress in a textarea?

thanks,

--
,_,
(O,O)
( )
---"-"-alex

推荐答案

2004年8月17日星期二10:35:36 +0200,znndrp < ER **** @ xs4all.no.spam>写道:
On Tue, 17 Aug 2004 10:35:36 +0200, znndrp <er****@xs4all.no.spam> wrote:
任何人都知道如何使用fireEvent在
textarea中模拟一个狗屎+按键?
Anyone knows how to use fireEvent to simulate a shit+keypress in a
textarea?




没有标准方法。 DOM 2事件规范定义了将HTML,鼠标和UI事件分派到文档树中的方式,但是未指定
键盘事件。 DOM 3事件规范确实是
添加键盘事件,但规范从未达成一致,所以

几个[1]浏览器实现了它。

这意味着你可以做的任何事情,*可能*在Mozilla和IE中工作,但是

它在其他任何地方都不太可能有效。


对不起,

Mike

[1] Mozilla做了,但他们的实施是早期的,属性

和方法已经改变从那以后。


-

Michael Winter

替换.invalid与.uk通过电子邮件回复



There is no standard approach. The DOM 2 Events Specification defined ways
of dispatching HTML, mouse, and UI events into the document tree, but
keyboard events were not specified. The DOM 3 Events Specification does
add keyboard events, but the Specification was never agreed upon, so
few[1] browsers implemented it.

That means that anything you might do, *might* work in Mozilla and IE, but
it''s highly unlikely to work anywhere else.

Sorry,
Mike
[1] Mozilla did, but their implementation was made early, and properties
and methods have changed since.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail


znndrp写道:
znndrp wrote:
任何人都知道如何使用fireEvent模拟一个狗屎+按键
textarea?
Anyone knows how to use fireEvent to simulate a shit+keypress in a
textarea?




您似乎只针对IE,因此该解决方案仅限IE。注意

触发按键事件不会处理内置的
事件前的机制,即你在textarea中看不到任何字母。对于操纵textarea值的

,使用IE范围。


虽然触发事件的想法很好,但我相信那里

通常是更好的方法,使用处理程序和代理,但不是

知道你想做什么使得很难确定最好的方法: - )
---

< form>

< textarea onkeypress =" foo(this,event)">< / textarea>

< input type =" button"值= QUOT;栏()" onclick =" bar()">

< / form>

< script type =" text / javascript">

函数foo(elem,evt){

alert(

[

" elem:" + elem .nodeName,

" shiftKey:" + evt.shiftKey,

" keyCode:" + evt.keyCode

]。加入(" \ n")

);

}


功能栏(){

if(document.createEventObject){

var evt = document.createEventObject();

evt.shiftKey = true;

evt .keyCode = 121;

document.forms [0] .elements [0] .fireEvent(" onkeypress",evt);

}

}

< / script>

---

HTH,

是的。



You seem to be targeting IE only, so the solution will be IE only. Note
that triggering a keypress event does not deal with the built-in
pre-event mechanics, i.e. you won''t see any letter in your textarea. As
for manipulating the textarea''s value, use IE ranges.

Though the idea of triggering events is a good one, I believe that there
usually are better approaches, using handlers and "proxies", but not
knowing what you want to do makes it difficult to determine the best one:-)
---
<form>
<textarea onkeypress="foo(this, event)"></textarea>
<input type="button" value="bar()" onclick="bar()">
</form>

<script type="text/javascript">
function foo(elem, evt){
alert(
[
"elem : " + elem.nodeName,
"shiftKey : " + evt.shiftKey,
"keyCode : " + evt.keyCode
].join("\n")
);
}

function bar(){
if(document.createEventObject) {
var evt=document.createEventObject();
evt.shiftKey=true;
evt.keyCode=121;
document.forms[0].elements[0].fireEvent("onkeypress", evt);
}
}
</script>
---
HTH,
Yep.


Yann-Erwan Perio写道:
Yann-Erwan Perio wrote:
znndrp写道:
znndrp wrote:
任何人都知道如何使用fireEvent在
textarea中模拟一个狗屎+按键?
Anyone knows how to use fireEvent to simulate a shit+keypress in a
textarea?



您似乎只针对IE,因此该解决方案仅限IE。注意
触发按键事件不会处理内置的事件前机制,即你在textarea中看不到任何字母。为了操纵textarea的值,使用IE范围。

虽然触发事件的想法很好,但我相信那里通常是更好的方法,使用处理程序和代理,但不知道你想做什么使得很难确定最好的一个: - )


You seem to be targeting IE only, so the solution will be IE only. Note
that triggering a keypress event does not deal with the built-in
pre-event mechanics, i.e. you won''t see any letter in your textarea. As
for manipulating the textarea''s value, use IE ranges.

Though the idea of triggering events is a good one, I believe that there
usually are better approaches, using handlers and "proxies", but not
knowing what you want to do makes it difficult to determine the best one:-)




我想我也不知道自己:)但我不认为这是我的问题的解决方案

。当我在阅读关于这个主题的更多内容时,我也注意到了

这里的方法名为''handleEvent()''。

fireEvent和handleEvent有什么区别?


-

,_,

(O,O)

()

---" - " -alex



I think I don''t know myself either :) But I don''t think this is the solution
to my problem. While I was reading some more on this subject I also noticed
there''s method called ''handleEvent()''. What''s the difference between
fireEvent and handleEvent?

--
,_,
(O,O)
( )
---"-"-alex


这篇关于fireEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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