zoukankan      html  css  js  c++  java
  • js实现div拖拽互换位置效果

    可以实现div拖拽互换位置,可以是多个div,div中放上img还是挺有用的

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title></title>
      <style type="text/css">
            #div1, #div2 {
                float: left;
                 100px;
                height: 35px;
                margin: 10px;
                padding: 10px;
                border: 1px solid #ccc;
                line-height:35px;
            }
        </style>
    <script type="text/javascript">
        function allowDrop(ev) {
            ev.preventDefault();
        }
        var srcdiv = null;
        var temp = null;
        //当拖动时触发
        function drag(ev, divdom) {
            srcdiv = divdom;
            temp = divdom.innerHTML;
        }
        //当拖动完后触发
        function drop(ev, divdom) {
            ev.preventDefault();
            if (srcdiv !== divdom) {
                srcdiv.innerHTML = divdom.innerHTML;
                divdom.innerHTML = temp;
            }
        }
    </script>
    </head>
    <body>
        <div id="div1" ondrop="drop(event,this)" ondragover="allowDrop(event)" draggable="true" ondragstart="drag(event, this)" style="">
                <p>我是第一!</p>
            </div>
        <div id="div2" ondrop="drop(event,this)" ondragover="allowDrop(event)" draggable="true" ondragstart="drag(event, this)" style="">
                <p>那我第二。</p>
            </div>
    </body>
    </html>
    

    文章转自这里

  • 相关阅读:
    Intellij IDEA 使用总结
    Apache Camel之FTP组件学习
    谈一谈EasyUI中TreeGrid的过滤功能
    JAVA实用案例之图片水印开发
    三、SolrCloud的搭建
    style里面设置变量
    for 循环中 break-continue 与label标签的使用
    vue ref的用法
    Vuex实践
    vue 数据动态响应(Vue.set方法)
  • 原文地址:https://www.cnblogs.com/gankehuang/p/11059006.html
Copyright © 2011-2022 走看看