日期:2014-05-16  浏览次数:20361 次

如何取得鼠标选中范围的链接?
在一个页面上,有很多链接。  

鼠标在上面选择,我想在下面的Textarea1   显示被选中的所有   链接名(即: <A> 链接名 </A> )

在     TextArea2   显示被选中的所有   链接地址   (即: <A   href= "链接地址 "> 链接名 </A> )

请教各位老大,   如何实现?


------解决方案--------------------
显示内容
<a href= "#test " onclick= "alert(this.innerText) "> test </a>
显示链接地址
<a href= "#test " onclick= "alert(this.href) "> test </a>

至于具体你要怎么实现就自己写代码吧
------解决方案--------------------
不知道这个是不是你想要的效果
<script>
function asd(){
document.getElementById( 'iii ').innerHTML=(document.selection.createRange().htmlText);
ol=document.getElementById( 'iii ').getElementsByTagName( 'a ');
//document.getElementById( "aaa ").value= " ";
var stra= " ",strb= " ";
for(i=0;i <ol.length;i++){
stra+=ol[i].href+ "\n ";
strb+=ol[i].innerText+ "\n ";
}
document.getElementById( "aaa ").value=stra;
document.getElementById( "bbb ").value=strb;
}
</script>
<body onmousemove= "asd() ">
<a href= "http://www.baidu.com " > dfsa </a>
<a href= "http://www.baidu.com " > dfsa </a>
<a href= "http://www.baidu.com "> dfsa </a>

<textarea id= "aaa " cols= "55 " rows= "15 "> </textarea>
<textarea id= "bbb " cols= "55 " rows= "15 "> </textarea>

<div name= "iii " id= "iii " style= "display:none "> </div>

你可以选中那些链接试试