0
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<script>
    $(this).select(function(){
        var a = $(this).prevUntil('p').html;
        console.log(a);
    });
</script>


<html>
    <p>dfdsf
        dsfdsf
        <span>sdfdsfds</span><a >sdfdsfdsfdsf</a>sdfsdfdsfdsfds
fsd
f
ds
f
ds
fd</p>
</html>

我需要从光标选择位置到第一个父级divp.

4

1 回答 1

0

尝试这样的事情:

$('p').mouseup(function(){
    if(window.getSelection().toString()!='')
        console.log(window.getSelection().toString());
});

演示:http: //jsfiddle.net/7Xbam/

于 2013-02-27T00:18:54.020 回答