<!DOCTYPE html> <html> <head> <meta charset='utf-8'> <title>test</title> <style src="text/css"> div{ width:80px; height:80px; position:absolute; left:100px; top:100px; background-color:red; } </style> <script src="js/jquery.js"></script> <script> window.onload = function(){ $('#btnok')[0].onclick = function(){ /* //1.获取div元素的位置 var json = $('div').offset(); alert(json.left+'-'+json.top); */ //2.设置元素的位置 var data = { left:200, top:200 }; $('div').offset(data); } } </script> </head> <body> <input type="button" id="btnok" value="class属性设置" /> <hr /> <div></div> </body> </html>