8.7w+
社区成员
var testLib={
testFun:function(callback){
$( ".selector" ).droppable({
drop: function( event, ui ) {
//这里想执行callback
}
}
}
});
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{margin:0;padding:0;}
#draggable{width:100px;height:100px;background-color:#a20000;}
#droppable{width:400px;height:400px;background-color:#ff6600;}
</style>
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.8.23/jquery-ui.min.js"></script>
</head>
<body>
<div id="draggable" class="ui-widget-content">
<p>Drag me to my target</p>
</div>
<div id="droppable" class="ui-widget-header">
<p>Drop here</p>
</div>
<script type="text/javascript">
$(document).ready(function() {
var testLib = {
testFun: function(callback) {
$("#draggable").draggable();
$("#droppable").droppable({
drop: function(event, ui) {
callback();
}
});
}
};
testLib.testFun(function() {
alert('1');
});
});
</script>
</body>
</html>
var testLib = {
testFun:function(callback){
$( ".selector" ).droppable({
drop: function( event, ui ) {
//这里想执行callback
callback();//直接執行啊,難道是我理解錯了?
}
}
}
});
$(function() {
$( "#draggable" ).draggable();
$( "#droppable" ).droppable({
drop: function( event, ui ) {
//callback
$( this ).addClass( "ui-state-highlight" )
.find( "p" )
.html( "Dropped!" );
}
});
});
<div id="draggable" class="ui-widget-content">
<p>Drag me to my target</p>
</div>
<div id="droppable" class="ui-widget-header">
<p>Drop here</p>
</div>