Here an example http://jsfiddle.net/naqbq/How do I grab current position for x and y after re-position the image?<input type="hidden" name="source_x" id="source_x" /><input type="hidden" name="source_y" id="source_y" /> 解决方案 In the stop callback, you can use ui.helper to access the dragged element. Then use offset on it, as Brad suggested:$("#image").draggable({ stop:function(event,ui) { var wrapper = $("#wrapper").offset(); var borderLeft = parseInt($("#wrapper").css("border-left-width"),10); var borderTop = parseInt($("#wrapper").css("border-top-width"),10); var pos = ui.helper.offset(); $("#source_x").val(pos.left - wrapper.left - borderLeft); $("#source_y").val(pos.top - wrapper.top - borderTop); alert($("#source_x").val() + "," + $("#source_y").val()); }});Then, it's just a matter of adjusting it to your wrapper - subtracting its offset and its border's width - and setting it to your input's val. (Edit: there it is! found the solution in another question)http://jsfiddle.net/mgibsonbr/naqbq/4/ 这篇关于如何从可拖动的jQuery UI中获得位置x和y?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-14 22:35