问题汇总

js代码中的如下box2为什么不需要先获取,也能也能移动box2的对象。

	var box1 = document.getElementById("box1");
				//获取btn01
				var btn01 = document.getElementById("btn01");
				//获取btn02
				var btn02 = document.getElementById("btn02");
				//点击按钮以后,使box1向右移动(left值增大)
				btn01.onclick = function(){
					move(box1 ,"left", 800 , 20);
				};
				//点击按钮以后,使box1向左移动(left值减小)
				btn02.onclick = function(){
					move(box1 ,"left", 0 , 10);
				};
				//获取btn03
				var btn03 = document.getElementById("btn03");
				btn03.onclick = function(){
					move(box2 , "left",800 , 10);
				};
		<button id="btn01">点击按钮以后box1向右移动button>
		<button id="btn02">点击按钮以后box1向左移动button>
		<button id="btn03">点击按钮以后box2向右移动button>
		<button id="btn04">测试按钮button>
		
		<br /><br />
		
		<div id="box1">div>
		<div id="box2">div>

你可能感兴趣的:(JavaScript)