$.ajax的success中如何添加代码var drag = function(obj) { obj.bind("mousedown", start); function start(event) { if (event.button == 0) { gapX = event.clientX - obj.offset().left; gapY = event.clientY - obj.offset().top; $(document).bind("mousemove", move); obj.bind("mouseup", stop); } return false; } function move(event) { obj.css({ "left": (event.clientX - gapX) + "px", "top": (event.clientY - gapY) + "px" }); return false; } function stop() { $(document).unbind("mousemove", move); $(document).unbind("mouseup", stop); } } obj = $(".image-editor"); drag(obj);
时间: 2024-01-03 10:03:41 浏览: 28
可以这样添加代码:
```
$.ajax({
url: 'your-url',
success: function(response) {
// your other code
var drag = function(obj) {
obj.bind("mousedown", start);
function start(event) {
if (event.button == 0) {
gapX = event.clientX - obj.offset().left;
gapY = event.clientY - obj.offset().top;
$(document).bind("mousemove", move);
obj.bind("mouseup", stop);
}
return false;
}
function move(event) {
obj.css({
"left": (event.clientX - gapX) + "px",
"top": (event.clientY - gapY) + "px"
});
return false;
}
function stop() {
$(document).unbind("mousemove", move);
$(document).unbind("mouseup", stop);
}
}
obj = $(".image-editor");
drag(obj);
}
});
```
这样,在ajax请求成功后,会执行success回调函数内的代码,其中包括了你提供的拖拽函数。