源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ x=$("p").position(); $("#span1").text(x.top); $("#span2").text(x.left); }); }); </script> </head> <body> <div style="border:1px solid black;padding:100px;margin:50px;"> <p>这一段的位置(相对于它的父元素)是<span id="span1">x</span> top 和 <span id="span2">x</span> left.</p> <button>获取位置</button> </div> </body> </html>
运行结果: