开发者

handle multiple event in web control

How to handle multiple event in web control using javascript for ex handling开发者_开发技巧 onpaste and on keyup event in textarea


There's no special trick to assigning different event handlers to an element, just define them as you would:

var tArea = document.getElementById("myTextArea");

// Define `onpaste` handler - note that Opera doesn't support `onpaste`
tArea.onpaste = function (evt) {
}

// Define `onkeyup` handler
tArea.onkeyup = function (evt) {
}

If you want to assign multiple functions to the same event, you need to use attachEvent for IE and addEventListener for other browsers.


You can add as many event handlers as you need to an element.

element.addEventListener('event-type', handler1, true);
element.addEventListener('another-type', handler2, true);
element.addEventListener('third-type', handler3, true);

function handler1( e ){}
function handler2( e ){}
function handler3( e ){}

Of course this is different in ie.

element.attachEvent('onevent-type', handler1);
element.attachEvent('onanother-type', handler2);
element.attachEvent('onthird-type', handler3);

so you'll have to code around that or use a library

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜