首页 > 学院 > 开发设计 > 正文

获取被拖动的对象的ID

2019-11-17 04:48:10
字体:
来源:转载
供稿:网友
<!DOCTYPE Html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="KeyWords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD><BODY>
<SCRIPT LANGUAGE="javascript">
<!--
var ie=document.all;
var nn6=document.getElementById&&!document.all;
var isdrag=false;
var y;
var dobj;function movemouse(e)
{
  if (isdrag)
  {
    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    return false;
  }
}function selectmouse(e)
{
  var fobj = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? "HTML" : "BODY";
  while (fobj.tagName != topelement && fobj.className != "dragme")
  {
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }
  if (fobj.className=="dragme")
  {
    isdrag = true;
    dobj = fobj;
 //alert(dobj.id);显示被拖动图片的ID
    ty = parseInt(dobj.style.top+0);
    y = nn6 ? e.clientY : event.clientY;
    document.onmousemove=movemouse;
    return false;
  }
}
document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");
//-->
</SCRIPT>
<style>.dragme{position:relative;}</style><img src="images/1.jpg" id="image1" class="dragme">
<img src="images/2.jpg" id="image2" class="dragme">
<img src="images/3.jpg" id="image3" class="dragme"></BODY>
</HTML>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表