Javascript 获取突出显示的文本

Javascript 获取突出显示的文本,javascript,jquery,asp.net,highlight,selectedtext,Javascript,Jquery,Asp.net,Highlight,Selectedtext,当我在中选择一些文本时,我希望突出显示的文本显示在div正下方的文本框中。我该怎么做 <div> My text goes here. </div> <asp:TextBox ID="txt" runat="server"/> 我的文本在这里。 工作演示或使用DIV演示 <textarea>Some default text; HUlk is very cool innit</textarea> <br/> &

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

<div>
    My text goes here.
</div>
<asp:TextBox ID="txt" runat="server"/>

我的文本在这里。

工作演示或使用DIV演示

<textarea>Some default text; HUlk is very cool innit</textarea>
<br/>

<input type="text" id="hulk" />
​
。在
API上:

我已经为你定制了它

好链接:还有一个大提示:

希望演示能帮助你,让我知道我错过了什么<代码>:)

代码

$('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

<textarea>Some default text; HUlk is very cool innit</textarea>
<br/>

<input type="text" id="hulk" />
​
一些默认文本;绿巨人很酷,不是吗

图像

$('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;
}​

工作演示或使用DIV演示

<textarea>Some default text; HUlk is very cool innit</textarea>
<br/>

<input type="text" id="hulk" />
​
。在
API上:

我已经为你定制了它

好链接:还有一个大提示:

希望演示能帮助你,让我知道我错过了什么<代码>:)

代码

$('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

<textarea>Some default text; HUlk is very cool innit</textarea>
<br/>

<input type="text" id="hulk" />
​
一些默认文本;绿巨人很酷,不是吗

图像

$('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;
}​

可能的重复不是真的,因为这个地址与asp接口(虽然没有标记)可能的重复不是真的,因为这个地址与asp接口(虽然没有标记)@explorer hiya什么不起作用?flick me lil更多详细信息
:)
会帮助您吗?当我从文本区域选择文本时,我无法在文本框中找到它。@explorer coleus,我已经尝试过多次,现在在mac osx safari中工作正常吗?请其他人检查一下,干杯!我添加了screeshot以获取详细信息:)我正在Mozilla firefox和Internet explorer中尝试。这里没用。@explorer哈哈哈,okies,很高兴能帮上忙!我已经让nbrooks和blaster再确认一下,cheers@explorer嗨,什么不起作用了,兄弟?flick me lil更多详细信息
:)
会帮助您吗?当我从文本区域选择文本时,我无法在文本框中找到它。@explorer coleus,我已经尝试过多次,现在在mac osx safari中工作正常吗?请其他人检查一下,干杯!我添加了screeshot以获取详细信息:)我正在Mozilla firefox和Internet explorer中尝试。这里没用。@explorer哈哈哈,okies,很高兴能帮上忙!我已经请nbrooks和blaster再次确认,干杯