Body页面
<button type="button" id="btn1">按钮</button>
<button type="button" id="btn2">向左移动</button>
<div style="width: 100px; height: 100px; background-color: orange; position: absolute; left: 0px;"id="box1"></div>
方法
<script type="text/javascript">
//注册Onload事件
window.onload=function(){
//获取按钮
var btn1=document.getElementById("btn1");
//为按钮添加单击事件
btn1.onclick=function(){
var box=document.getElementById("box1");
box.style.left=parseInt(box.style.left)+100+"px";
}
var btn2=document.getElementById("btn2");
btn2.onclick=function(){
var box=document.getElementById("box1");
box.style.right=parseInt(box.style.right)+100+"px";
}
}
</script>