我有三个按钮,我想将它拖放到droppable div中,但它不起作用。请查看我的代码并建议我最好
<body>
<form method="post" action="Dashboard.aspx" id="form1">
<script type="text/javascript">
$('#play1').draggable();
$('#Yasin2').draggable();
$('#page3').draggable();
$('#page24').draggable();
$('#divScene').droppable({
drop: function (event, ui){
var ID = $(ui.draggable).attr('id');
alert(ID);
}
});
</script>
<div>
<input type="submit" name="btnAddScene" value="Add" id="btnAddScene" style="float:right; height: 26px;">
<h1>Scene(s)</h1>
</div>
<div id="divScene" class="ui-droppable" style="border-style:solid; border-width:5px; padding:20px 20px 20px 20px;">
<input type="button" class="ui-draggable" name="play1" value="play" onclick="return false;__doPostBack('play1','')" id="play1" class="ui-widget ui-state-default ui-corner-all" title="Scene">
<input type="button" class="ui-draggable" name="Yasin2" value="Yasin" onclick="return false;__doPostBack('Yasin2','')" id="Yasin2" class="ui-widget ui-state-default ui-corner-all" title="Scene">
<input type="button" class="ui-draggable" name="page3" value="page" onclick="return false;__doPostBack('page3','')" id="page3" class="ui-widget ui-state-default ui-corner-all" title="Scene">
<input type="button" class="ui-draggable" name="page24" value="page2" onclick="return false;__doPostBack('page24','')" id="page24" class="ui-widget ui-state-default ui-corner-all" title="Scene">
</div>
</form>
</body>
</html>
答案 0 :(得分:0)
首先,您需要在页面中包含jQuery和jQuery UI:
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
之后,您需要将jQuery代码包装在 DOM ready 处理程序$(function() {...});
中,以确保在执行jQuery代码之前已正确加载所有DOM元素:
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script>
$(function () {
$('#play1').draggable();
$('#Yasin2').draggable();
$('#page3').draggable();
$('#page24').draggable();
$('#divScene').droppable({
drop: function (event, ui) {
var ID = $(ui.draggable).attr('id');
alert(ID);
}
});
});
</script>
答案 1 :(得分:0)
错误是可拖动的,并且droppable不能在按钮上工作,它仅适用于div。