汇智学堂-JS菜鸟版过河小游戏(之二---测试父母上船)

上船界面见下图:
汇智学堂-JS菜鸟版过河小游戏(之二---测试父母上船)
页面修改代码

<div id="div1" class="a1">
			<img src="img/father.jpg" "fathermove1()" />
		</div>	
		
		<div id="div2" class="a2">
			<img  src="img/mother.jpg" "mothermove1()"/>
		</div>
<div>

JS函数:

<!--上船-->

var shipposition1=0;
var shipposition2=0;

function upship(div11){
	var div1=document.getElementById(div11);
	
	if(div1.style.marginLeft=="0px"||div1.style.marginLeft==""){
		div1.style.marginTop="600px"; 
		if(shipposition1==0){		
	  	 div1.style.marginLeft="210px";	
	  	 shipposition1=1;
	   }
		else if(shipposition2==0){
		 div1.style.marginLeft="110px";	
		 shipposition2=1;
	   }
		else{
			alert('船上人已满!');
		}
  }
}

<!--爸爸上船-->

function fathermove1(){
	upship("div1");	
}
<!--妈妈上船-->
function mothermove1(){
	upship("div2");
}
`