<分区>
所以我正在尝试使用 jquery 使元素可拖动,但它在这里不起作用是代码
<html>
<head>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<style>
#console {
background-color: #000000;
}
</style>
</head>
<body>
<div id="console">
</div>
<script>
$(function() {
$( "#draggable" ).draggable();
});
</script>
</body>
</html>
最佳答案
你需要一个元素
来拖动。不存在任何具有 id
draggable
且您为其实例化 dragging
的此类元素。我假设您想使用 id
console
拖动 div
,因此您需要在该特定元素上初始化 draggable
,例如$( "#console").draggable();
.以下是工作片段
$(function() {
$("#console").draggable();
});
#console {
background-color: #000000;
width: 300px;
height: 300px;
}
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div id="console">
</div>
关于javascript - Jquery 可拖动不工作 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37476515/