首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

怎么取得鼠标选中范围的链接

2012-02-27 
如何取得鼠标选中范围的链接?在一个页面上,有很多链接。鼠标在上面选择,我想在下面的Textarea1显示被选中的

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

鼠标在上面选择,我想在下面的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>

你可以选中那些链接试试

热点排行
Bad Request.