我需要一个示例,该示例使用jquery使用ajax将<div>
的当前x,y位置(左上像素)发送到php文件,然后可以处理该位置。
Assuming a recent version of JQuery, you could use the following given the ID of your div is "divName":
$("#divName").offset();
For reference: http://docs.jquery.com/CSS/offset
var cX = 0; var cY = 0; //Follow mouse around.. (platform independent, based on document dimensions, not window) $().mousemove(function(e){ cX = e.pageX; cY = e.pageY; });
Then, just use the cX and cY variables as you need. It automatically accounts for scrolling offsets. Very easy/handy, DHTML never worked so well!
if you only need it on a certain element, you can grab it using the simple css style selectors, eg's:
$("#myid").mousemove... $(".myclass").mousemove... $("table tr").mousemove... $(".interestingdivclass .subclass input:checkbox").mousemove...
The following question has the ajax component:
对于x,y坐标,您可以使用尺寸插件(位置函数): http : //docs.jquery.com/Plugins/dimensions
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.