将所选文本从一个文本区域复制到另一个文本区域

我有两个

最后,剧本:

 var selText = ""; $( document ).ready( function() { $( '#theButton' ).mousedown( function() { $( '#selection' ).val( getSelectedText() ); }); }); function getSelectedText(){ if ( window.getSelection ) { return window.getSelection().toString(); } else if ( document.getSelection ) { return document.getSelection(); } else if ( document.selection ) { return document.selection.createRange().text; } } 

为了给予应有的充分信用,我从http://esbueno.noahstokes.com/post/92274686/highlight-selected-text-with-jquery获得了getSelectedText()方法。

使用jquery,您可以执行以下操作

  $('#selection').val($('#input').val()); 

http://api.jquery.com/val/

Interesting Posts