當前位置:編程學習大全網 - 站長素材 - 如何用HTML和JS實現選座位,想要效果如下

如何用HTML和JS實現選座位,想要效果如下

<!DOCTYPE?HTML>

<html>

<head>

<title>Page?Title</title>

<meta?http-equiv="Content-Type"?content="text/html;?charset=UTF-8"?/>

<script>

var?row=2,col=11,size=20,gap=5;

window.onload=function(){

var?wrap=document.createElement("div");

wrap.style.margin="0?auto";

wrap.style.width=(size+gap)*col+"px";

for(var?i=0;i<row;i++){

var?rows=document.createElement("div");

rows.style.float="left";

rows.style.marginBottom=gap+"px";

for(var?j=0;j<col;j++){

var?div=document.createElement("img");

div.src="a.png";

div.style.width=size+"px";

div.style.height=size+"px";

div.style.float="left";

div.style.marginLeft=gap+"px";

div.onclick=function(){

!this.abc?this.src="b.png":this.src="a.png";

this.abc=!this.abc;

}

rows.appendChild(div);

}

wrap.appendChild(rows);

}

document.body.appendChild(wrap);

}

</script>

</head>

<body>

</body>

</html>

  • 上一篇:與起點有關的名人故事有哪些?
  • 下一篇:求PS摳圖好教程!要有圖的!!!!!
  • copyright 2024編程學習大全網