1

我遇到了这个代码的麻烦

$(document).on('mouseup','.editor p',function(e){
             var id = $(this).attr('name');

             var $text = window.getSelection(this);
             var al =$(this).find('a').length;
             if($(this).text($text).w)
});

如何mouseup根据以下文本选择一个锚标记:

<div class="editor">
<p name="909037734">It is a long established fact that a reader will be distracted by the 
readable content of a page when looking at its layout. The point of 
using <a id="14998538924729" title="Click to follow link" class="pinkLink" target="_blank" href="http://google.com">Lorem Ipsum</a> is that it has a more-or-less normal distribution of 
letters, as opposed to using 'Content here, content here', making it 
look like readable English. Many desktop publishing <a id="93420055379223" title="Click to follow link" class="pinkLink" target="_blank" href="http://facebook.com">packages</a> and web 
page editors now use Lorem Ipsum as their default model text, and a 
search for 'lorem ipsum' will uncover many web sites still in their 
infancy. Various versions have evolved over the years, sometimes by 
accident, sometimes on purpose (injected <a id="52337704157880" title="Click to follow link" class="pinkLink" target="_blank" href="http://yahoo.com">humour</a> and the like).</p></div>

请告诉我这件事。

4

3 回答 3

1

看看下面的 JS fiddle

希望这是你想要的

http://jsfiddle.net/arunberti/z97br/1/

$(document).on('mouseover','.editor p',function(e)
    {
    if(e.target.text!=undefined)
    {
            alert(e.target.text);
    }
});
于 2013-08-01T06:23:11.930 回答
1

试试这个 :

$(document).on('mouseup','.editor p',function(e){
    if(e.target.text!=undefined){
        $("#"+e.target.id).before($("#"+e.target.id).html());
        $("#"+e.target.id).remove();
    }
});

演示在这里

希望它会有所帮助

于 2013-08-01T06:47:36.390 回答
0

做这样的事情:

var al = $(this).find('a');
al[1].click();//OR what erver you prefer
于 2013-08-01T06:25:41.167 回答