由于某些原因,即使我启用了div,div中的div块也无法拖动。
的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>
我的box_holder里面的东西是不可拖动的,为什么会这样?
此后的另一个问题是如何将项目拖动到另一个div框。
我的另一个div框:
<div id="dragBox" >
<div id="dragBoxTitle" >
Pick Your Numbers:
</div>
</div>
以下所有代码均按顺序排列:
<!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>
我的CSS代码:
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;
}
答案 0 :(得分:1)
更新:您缺少jQuery UI库,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>
您将boxes_holder
元素设置为可拖动,而不是其中的div。
尝试
$(document).ready(function() {
$("#boxes_holder > .boxes").draggable();
});
演示:Fiddle
答案 1 :(得分:1)
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#boxes_holder").draggable();
});
</script></head>
<body>
<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>
</body>
</html>