最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

internet explorer - IE onPaste event using JavaScript not HTML - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited Apr 27, 2022 at 21:12 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Feb 13, 2009 at 17:38 Robin BarnesRobin Barnes 13.6k15 gold badges45 silver badges45 bronze badges 1
  • jScript is JavaScript - it's just what Microsoft calls its implementation. – MrWhite Commented Jan 26, 2012 at 14:47
Add a ment  | 

2 Answers 2

Reset to default 3

Try lowercase:

document.getElementById('text_area').onpaste = ...

It is down to capitalisation, you want:

document.getElementById('text_area').onpaste = function() { alert('I iz in ur textbox, pasting some text') };
发布评论

评论列表(0)

  1. 暂无评论