<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
li{ margin:10px; width:100px; height:30px; list-style:none; background:yellow;}
#div1{ width:200px; height:200px; background:red; margin:200px;}
</style>
<script type="text/javascript">
//拖放 draggable :设置为true 就可以拖放了
//拖拽元素事件:ondragstart 拖拽前触发
//ondrag 拖拽之间触发
//ondragend 拖拽结束触发
window.onload=function(){
var aLi=document.getElementsByTagName("li");
var oDiv=document.getElementById("div1");
var i=0;
for(var i=0;i<aLi.length;i++)
{
aLi[i].ondragstart=function()//拖拽前触发
{
this.style.background="green";
}
aLi[i].ondrag=function()//开始与结束连续触发
{
//document.title=i++;
}
aLi[i].ondragend=function()//拖拽结束触发
{
this.style.background="yellow";
}
}
//目标元素事件:
//ondragenter 进入目标元素触发,相当于mouseover
//ondragover 进入目标,离开目标之间,连续触发
//ondragleave 离开目标元素触发,相当于mouseout
//drop 在目标元素上释放鼠标触发 oDiv.ondragenter=function()
{
this.style.background="green";
}
oDiv.ondragover=function(ev)//enter和leave之间触发
{
//document.title=i++;
ev.preventDefault();
} oDiv.ondragleave=function()
{
this.style.background="red";
}
oDiv.ondrop=function()
{
alert(123);//要想触发ondrop事件,就必须阻止ondragover默认事件。
} //事件执行顺序:drop不触发的时候
//dragstart>drag>dragenter>dragover>dragleave>dragend
//事件执行顺序: drop触发的时候(dragover的时候阻止默认事件)
//dragstart>drag>dragenter>dragover>drop>dragend
}
</script>
</head> <body>
<ul>
<li draggable="true">a</li>
<li draggable="true">b</li>
<li draggable="true">c</li>
</ul>
<div id="div1"></div>
</body>
</html>

最新文章

  1. 报表软件JS开发引用HTML DOM的location和document对象
  2. RMQ 训练 之 codevs 1690 开关灯 已经搞定
  3. Hibernate 检索方式
  4. boost状态机学习二(秒表)
  5. VCL Tclientsocket, Tserversocket控件安装方法
  6. List&lt;IPoint&gt; to IPointCollection to IPolygon
  7. SWFUpload接受服务器Action返回的参数
  8. 获得自动增长的MySQL主键
  9. Eclipse使用Maven创建普通Java工程时错误:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE from any of the configured repositories.
  10. ACCP6.0 教程课件,可用
  11. nefu 753 n!末尾有多少个0
  12. 打包ideaUI本地项目,以供本地使用
  13. VBA解析Json(转)
  14. js截取url参数
  15. SQL Server 2012安装时报错,错误 0x80070422怎么解决?解决方法。
  16. Android四大组件应用系列——Activity与Service交互实现APK下载
  17. 在windows、linux中开启nginx的Gzip压缩大大提高页面、图片加载速度&lt;转&gt;
  18. springboot 程序发布到tomcat运行
  19. Windows Server 2012无法安装 .NET3.5-安装角色或功能失败,找不到源文件
  20. python 几个重要的概念

热门文章

  1. Vue之数据传递
  2. HDU 3488 KM Tour
  3. UVa 579 Clock Hands
  4. Python之多线程与多进程(二)
  5. Python选修课第二届Turtle绘图大赛~~画猫猫
  6. Android之高效率截图
  7. 浅谈抓取网页数据(奉上Demo)
  8. 用上GIT你一定会爱上他
  9. rocketmq源码分析2-broker的消息接收
  10. activemq的安装启动