dongqian2021 2013-11-06 02:57
浏览 14
已采纳

Jquery中的可拖动项目

For some reasons, my div blocks that are inside the div aren't draggable even when I have enabled them.

Javascript

<script type="text/javascript">
$(document).ready(function() {

$("#boxes_holder").draggable();
});
</script>

HTML / PHP

<div id = "boxes_holder" class = "initBox">
<?php
//Creates 49 BOXES elements
    $x = 49;
    for($i=1; $i<=$x; $i++){
       echo '<div id="'.$i.' " draggable="true" class="boxes" style="text-align:center;" > '.$i.'</div>';
        }
?>
</div>

The stuff inside my boxes_holder arent draggable, why is that?

Another problem following this one is how one could possibly drag items to another div box.

My other div box:

<div id="dragBox" >
<div id="dragBoxTitle" >
    Pick Your Numbers:
</div>
</div>

All my code below are in order:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


<link rel="stylesheet" href="./css/hw2.css" type="text/css" media="screen" />

<script type="text/javascript"     src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>


<script type="text/javascript">


$(document).ready(function() {
$("#boxes_holder > .boxes").draggable();
});


</script>

</head>

<body>
<div id="mainbody">
<h3>Lotto 6/49 Combinations Finder</h3>


<div id = "boxes_holder" class = "initBox">
<?php
//Creates 49 BOXES elements
    $x = 49;
    for($i=1; $i<=$x; $i++){
       echo '<div id="'.$i.' " draggable="true" class="boxes" style="text-    align:center;" > '.$i.'</div>';
    }
?>
</div>



<div id="dragBox" >
<div id="dragBoxTitle" >
    Pick Your Numbers:
</div>
</div>
</div>
</body>
</html>

My CSS Code:

body {
padding:0;
margin:0;
font-size: 12px;
font-family: arial, sans-serif;  
color:#000;
cursor:auto;
}

#mainbody {
display:block;
width: 980px;
position: relative;
margin: 40px auto;
}

#mainbody h3{
font-size:24px;
color: blue;
}


#dragBox {
width:400px;
height:250px;
border:0px;
display: inline-block;
float: right;
vertical-align:top;
background-color:#FBFBFB;
}

#dragBoxTitle{
font-weight:bold;
font-size: 150%;
padding: 5px;
background-color: #D0D0D0;
border:1px solid #A9A9A9;
margin: 15px;
vertical-align:top;
}

.boxes {
width: 60px; 
height: 50px;
border:1px solid #A9A9A9;
line-height: 45px;
color: #FF0000;
padding:1px;
margin: 1px;
}


#boxes_holder{
width: 500px; 
height: 500px;
display: inline-block;

}
  • 写回答

2条回答 默认 最新

  • dongye7231 2013-11-06 02:58
    关注

    Update: You are missing the jQuery UI library, the draggable feature is provided by jQuery UI

    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/redmond/jquery-ui.css" media="screen" />
    <link rel="stylesheet" href="./css/hw2.css" type="text/css" media="screen" />
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.js"></script>
    

    You are making the boxes_holder element as draggable, not the div's inside it.

    Try

    $(document).ready(function() {
        $("#boxes_holder > .boxes").draggable();
    });
    

    Demo: Fiddle

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿