jquery 拖拽复制

在这里插入图片描述

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jqeruy UI 拖拽练习</title>


    <style>
        table {
            border-collapse: collapse;
        }

            table td {
                empty-cells: show;
            }
    </style>

</head>

<body>

    <h2>
        拖动复制例子</h3>
            <table border="2">
                <tr height="40">
                    <td id="dragg1" width="110" bgcolor="peru">复制1</td>
                    <td id="dragg2" width="110" bgcolor="lightgreen">复制2</td>
                    <td id="dragg3" width="110" bgcolor="salmon">复制3</td>
                </tr>
            </table>
        <table>
            <tr>
                <td>
                    <table border="2">
                        <tr height="40">
                            <td width="150">a1</td>
                            <td width="150">a2</td>
                            <td width="150">a3</td>
                            <td width="150">a4</td>
                        </tr>
                        <tr height="40">
                            <td width="150" id="innerBox11"></td>
                            <td width="150" id="innerBox12"></td>
                            <td width="150" id="innerBox13"></td>
                            <td width="150" id="innerBox14"></td>
                        </tr>
                        <tr height="40">
                            <td width="150" id="innerBox21"></td>
                            <td width="150" id="innerBox21"></td>
                            <td width="150" id="innerBox21"></td>
                            <td width="150" id="innerBox21"></td>
                        </tr>
                        <tr height="40">
                            <td width="150" id="innerBox31"></td>
                            <td width="150" id="innerBox31"></td>
                            <td width="150" id="innerBox31"></td>
                            <td width="150" id="innerBox31"></td>
                        </tr>
                        <tr height="40">
                            <td width="150" id="innerBox41"></td>
                            <td width="150" id="innerBox41"></td>
                            <td width="150" id="innerBox41"></td>
                            <td width="150" id="innerBox41"></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <!--导入jquery插件-->
        <script type="text/javascript" src="https://www.jq22.com/demo/jquery-tdfz20160803/jQuery1.11.3.min.js"></script>
        <!--导入jqueryUI插件-->
        <script type="text/javascript" src="https://www.jq22.com/demo/jquery-tdfz20160803/jquery-ui.js"></script>
        <script type="text/javascript" language="javascript">
   //在页面加载完之后加载jquery
   $().ready(function(e) {
       //拖拽复制体
       $('td[id^="dragg"]').draggable({
		   helper:"clone",
		   cursor: "move"
		 });

		//释放后
	   $('td[id^="innerBox"]').droppable({
			drop:function(event,ui){
				$(this).children().remove();
				var source = ui.draggable.clone();
			    $('<span style="color:red;" onclick = "javascript: $(this).parent().remove();" >   删除</span>', {
					style:'display:none',
				}).appendTo(source);


				source.mouseenter(function () {
				    $(this).find("span").show();
				});

				source.mouseleave(function () {
				    $(this).find("span").hide();
				});

				$(this).append(source);

			}
		});
     });
        </script>
        <!--自写脚本-->
        
        </body>
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值