2013-10-28 244 views
0

当我选择一些文本时,它被复制到textarea。但是,如果我在某个div中指向某处,它会复制所有div吗?而不仅仅是我选择的文本。 我有此:突出显示div

$(document).ready(function() { 
    $(document).bind("mouseup", function() { 
     var sel = $.selection('html'); 
     if (sel != '') { 
      $('#yourTextAreaId').val(sel); 
      $('#yourDivId').html(sel); 
     } 
    }); 
}); 

谢谢!

回答

2

您可以使用jQuery的.text()属性来获取节点的文本内容,然后您可以放置​​到textarea中。

$("yourselector").click(function(){ 
    $("#yourTextAreaId").val($(this).text()); 
}); 
0

要选择div的文本试试这个:

$(document).on('click',function(event){ 
    var text = event.target.innerHTML; 
    console.log(text); 
}); 

为了突出格,你可以试试这个:

$(document).on('click',function(event){ 
    var text = event.target.style.background='yellow'; 
}); 
0
$("#yourDivId").click(function() { 
    $("#yourTextAreaId").val($(this).html()); 
});