为什么这个显示浮点数
代码发一下
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> *{ margin: 0; padding: 0; } .container{ width: 300px; height: 200px; border: 2px solid #000; margin-left: 100px; position: relative; } .box { width: 100px; height: 100px; padding: 15px; background-color: red; position: absolute; left: 10px; top: 10px; } </style> <script src="./js/jquery-3.6.1.min.js"></script> </head> <body> <div class="container"> <div class="box"></div> </div> <p class="text1"></p> <p class="text2"></p> <script> var position = $(".box").position(); var offset = $(".box").offset(); $(".text1").text("left: " + position.left + ", top: " + position.top); $(".text2").text("left: " + offset.left + ", top: " + offset.top); </script> </body> </html>
换个浏览器试一下啊