js问题,如何当鼠标停留到某个连接上时获得当前鼠标位置和连接地址,并存入变量
1个回答
展开全部
<html>
<head>
<script language="javascript" type="text/javascript">
<!--
var domType = '';
if (document.all) {
domType = "ie4";
} else if (document.getElementById) {
domType = "std";
} else if (document.layers) {
domType = "ns4";
}
function initMouseMove(){
if(!document.all){
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = mouseMove;
}
function mouseMove(e){
var x,y;
if(!document.all){
fetch_object("txt").value="move";
//fetch_object("txt2").value="move";
x=e.pageX;
y=e.pageY;
}else{
x=document.body.scrollLeft+event.clientX;
y=document.body.scrollTop+event.clientY;
//z=document.all.links[0].outerHTML;
}
links=document.all.tags("A");
//document.write("<font size='2'>"+links[0].outerHTML+"</font><br>")
fetch_object("txt").value=x+":"+y;
//fetch_object("txt2").value=document.links.innerText;
}
var objects=new Array();
function fetch_object(idname, forcefetch) {
if (forcefetch || typeof(objects[idname]) == "undefined") {
switch (domType) {
case "std": {
objects[idname] = document.getElementById(idname);
}
break;
case "ie4": {
objects[idname] = document.all[idname];
}
break;
case "ns4": {
objects[idname] = document.layers[idname];
}
break;
}
}
return objects[idname];
}
-->
</script>
<title>get mouse position</title>
</head>
<body onload="initMouseMove()">
鼠标位置:<input id="txt"/>
链接地址:<input id="txt2"/>
<br>
(暂时没有找到如何获取鼠标当前所指向的链接地址的方法)
<br>
<br>
<a href="dd" >abc</a>
<a href="11">123</a>
</body>
</html>
复制以上代码。
暂时没有找到如何获取鼠标当前所指向的链接地址的方法,不好意思。
和楼主提出的问题类似有:
http://bbs.blueidea.com/thread-1853209-1-989.html
希望有熟悉JAVASCRIPT的朋友在以上代码的基础上更改。帮忙解决(使txt2文本框能够获得),谢谢!
<head>
<script language="javascript" type="text/javascript">
<!--
var domType = '';
if (document.all) {
domType = "ie4";
} else if (document.getElementById) {
domType = "std";
} else if (document.layers) {
domType = "ns4";
}
function initMouseMove(){
if(!document.all){
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = mouseMove;
}
function mouseMove(e){
var x,y;
if(!document.all){
fetch_object("txt").value="move";
//fetch_object("txt2").value="move";
x=e.pageX;
y=e.pageY;
}else{
x=document.body.scrollLeft+event.clientX;
y=document.body.scrollTop+event.clientY;
//z=document.all.links[0].outerHTML;
}
links=document.all.tags("A");
//document.write("<font size='2'>"+links[0].outerHTML+"</font><br>")
fetch_object("txt").value=x+":"+y;
//fetch_object("txt2").value=document.links.innerText;
}
var objects=new Array();
function fetch_object(idname, forcefetch) {
if (forcefetch || typeof(objects[idname]) == "undefined") {
switch (domType) {
case "std": {
objects[idname] = document.getElementById(idname);
}
break;
case "ie4": {
objects[idname] = document.all[idname];
}
break;
case "ns4": {
objects[idname] = document.layers[idname];
}
break;
}
}
return objects[idname];
}
-->
</script>
<title>get mouse position</title>
</head>
<body onload="initMouseMove()">
鼠标位置:<input id="txt"/>
链接地址:<input id="txt2"/>
<br>
(暂时没有找到如何获取鼠标当前所指向的链接地址的方法)
<br>
<br>
<a href="dd" >abc</a>
<a href="11">123</a>
</body>
</html>
复制以上代码。
暂时没有找到如何获取鼠标当前所指向的链接地址的方法,不好意思。
和楼主提出的问题类似有:
http://bbs.blueidea.com/thread-1853209-1-989.html
希望有熟悉JAVASCRIPT的朋友在以上代码的基础上更改。帮忙解决(使txt2文本框能够获得),谢谢!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询