我是JQuery
的新手,我正在尝试使用Draggable插件创建一个示例页面。页面加载正常,但我无法将<div>
标记拖到任何位置。我一直试图复制这个demo。这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<style type="text/css">
#draggable { width: 150px; height: 150px; padding: 0.5em; border: solid 1px black; cursor:pointer;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<script src="scripts/jquery.js" type="text/javascript"/>
<script src="scripts/jquery.ui.core.js" type="text/javascript"/>
<script src="scripts/jquery.ui.draggable.js" type="text/javascript"/>
<script src="scripts/jquery.ui.mouse.js" type="text/javascript"/>
<script src="scripts/jquery.ui.widget.js" type="text/javascript"/>
<script src="scripts/jquery-ui-1.8.13.custom.js" type="text/javascript" />
<script type="text/javascript">
$(document).ready(function() {
$("#draggable").draggable();
});
</script>
<div class="demo" style="height: 500px; width: 500px;">
<div id="draggable">
<p>Drag me around</p>
</div>
</div>
</div>
</form>
</body>
</html>
我只是想做到这一点,所以我可以将“draggable”<div>
拖到它周围的“demo”<div>
周围。谁能看到我错过的东西?
答案 0 :(得分:3)
您是否在网页上添加了jQuery UI脚本? Here is CDN link to the latest versions.
我使用Html5Boilerplate最佳做法:
</form>
<!-- Javascript at the bottom for fast page loading -->
<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.js" type="text/javascript"></script>
<script type="text/javascript"> window.jQuery || document.write('<script src="js/libs/jquery-1.6.1.js">\x3C/script>')</script>
<!-- Grab Google CDN's jQuery UI, with a protocol relative URL; fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript"> $.ui || document.write('<script src="js/libs/jquery-ui-1.8.12.custom.min.js">\x3C/script>')</script>
<!-- Scripts concatenated -->
<script src="js/plugins.js" type="text/javascript"></script>
<script src="js/script.js" type="text/javascript"></script>
<!-- End scripts -->
</body>
答案 1 :(得分:0)
对于它的价值,这是我的代码,我能够工作。我只需要包含2个javascript文件(其中一个我已经包含,另一个是jquery-ui.js,来自here,感谢@Scott!)。此外,@ DarthJDG是正确的,订单 DOES 很重要。如果我切换两个脚本标签的顺序,则分页。我只包括标签,因为其他一切都保持不变。再次感谢大家指出我正确的方向。这是我的代码:
<body>
<form id="form1" runat="server">
<div>
<%--came from http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.js--%>
<script src="scripts/jquery.js" type="text/javascript"></script>
<%--came from //ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.js--%>
<script src="scripts/jquery-ui.js" type="text/javascript" ></script>
<script type="text/javascript">
$(document).ready(function() {
$("#draggable").draggable({ containment: 'parent' });
});
</script>
<div class="demo" style="height: 500px; width: 500px;">
<div id="draggable">
<p>Drag me around</p>
</div>
</div>
</div>
</form>
</body>
答案 2 :(得分:0)
DownLoad来自http://jqueryui.com/download的完整JueryUI包,其中应包含wizard.js,core.js,mouse.js和draggable.js,然后使用$(control).draggable()使其正常工作。