简体   繁体   English

jQuery粘贴事件不起作用“实时”

[英]Jquery paste event dont work “live”

I am using this for catch paste evente on a textarea : 我正在使用它来在textarea上捕获粘贴事件:

$('textarea#id').on('paste', function (event) {
   alert('paste !');
});

It work fine on the page where the texteara is but it doesnt work if textarea#id is not already on the page, if I call it in ajax (like if its inside a remote modal). 它在texteara所在的页面上可以正常工作,但是如果textarea#id不在页面上(如果我在ajax中调用它(例如,它位于远程模态中)),则无法正常工作。

Change Script like this 像这样更改脚本

 $(function(){ $(document).on('paste', '#textArea', function () { alert('paste !'); }); }); 
 <html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <!DOCTYPE html> <body> <textarea rows="4" cols="50" id="textArea"> </textarea> </body> </html> 

Note :- The .on() method attaches event handlers to the currently selected set of elements in the jQuery object . 注意 :-. .on()方法将事件处理程序附加到jQuery object当前选择的元素集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM