我有這個小塊的代碼,我想模擬從一個點到另一個div的拖動..我用jquery.simulate.js腳本,但我得到錯誤在控制檯說.. 「$ .ui.mouse._mouseDown是不是一個函數」在jquery中模擬鼠標拖動
<html>
<head>
<style>
.box {
background-color:#b0c4de;
}
</style>
<script type="text/javascript" src="jquery-1.7.1.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="jquery.simulate.js"></script>
<script>
$(document).ready(function() {
var myDiv = $("#myDiv");
myDiv.draggable();
// This will set enough properties to simulate valid mouse options.
$.ui.mouse.options = $.ui.mouse.defaults;
var divOffset = myDiv.offset();
// This will simulate clicking down on the div - works mostly.
$.ui.mouse._mouseDown({
target: myDiv,
pageX: divOffset.left,
pageY: divOffset.top,
which: 1,
preventDefault: function() { }
});
});
</script>
</head>
<body>
<div id="myDiv">hello</div>
</body>
</html>
偉大的插件,真的很有用!感謝:-) – lorcan 2013-05-31 09:49:25
而你如何拖動到指定的元素?不是x/y – Nakilon 2015-11-24 17:42:39
@Nakilon查看[插件的文檔](https://github.com/j-ulrich/jquery-simulate-ext/blob/master/doc/drag-n-drop.md): '('#myDiv')。simulate(「drag-n-drop」,{dragTarget:otherDiv});' – Ignitor 2015-11-25 10:55:56