获取突出显示的文本

当我在

选择一些文本时,我希望突出显示的文本出现在div下方的文本框中。 我该怎么做?

 
My text goes here.

使用DIV演示 http://jsfiddle.net/KgtW5/3/

.on API: http : .on

我为你需要的人定制了它。

好的链接:和BIG提示: 获取突出显示/选定的文本

希望演示可以帮助你,知道我是否遗漏了什么! :)

 $('textarea').on('select', function() { var foo = getSelectionText(); $('#hulk').val(foo); }); function getSelectionText() { var text = ""; if (window.getSelection) { text = window.getSelection().toString(); } else if (document.selection && document.selection.type != "Control") { text = document.selection.createRange().text; } return text; }​ 

HTML

  

图片

在此处输入图像描述