IE onPaste event using javascript not HTML

2019-05-14 11:53发布

It seems that the only way to add an onPaste event to an input element is to use HTML:

<textarea id="text_area" onpaste="on_paste" />

rather than being able to attach the event handler using javascript:

document.getElementById('text_area').onPaste = function() { alert('I iz in ur textbox, pasting some text') };

The MSDN website says you can only add event handlers for onPaste using jscript or HTML, but I want to do it in javascript. Is there any way to do this?

2条回答
三岁会撩人
2楼-- · 2019-05-14 12:31

It is down to capitalisation, you want:

document.getElementById('text_area').onpaste = function() { alert('I iz in ur textbox, pasting some text') };
查看更多
对你真心纯属浪费
3楼-- · 2019-05-14 12:36

Try lowercase:

document.getElementById('text_area').onpaste = ...
查看更多
登录 后发表回答