资料
表格
制度
合同
管理
职场
经营
创业
范文
总结
计划
作文
文章
美文
词句
教程
模板
图片
字体
图标
办公
人事
财务
生产
管理资源吧首页
>>>
教程
>>>
编程
>>>
JavaScript教程
>>>
javascript 像素拼图实现代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JavaScript像素拼图游戏</title> <style type="text/css" media="all"> body{ margin:0px; padding:0px; background-color:#111111; font-family:Arial, Helvetica, sans-serif,"宋体"; } .container{ background-color:#CCCCCC; padding:0px 0px 0px 1px; width:609px; margin:0px auto; font-size:12px; height:auto; overflow:hidden; } .container .line,.container .line2{ width:100%; height:auto; overflow:hidden; } .container .line2 a{ color:#ababab; background-color:#666666; } .container a{ display:block; float:left; background-color:#999999; margin-right:1px; margin-top:1px; width:28px; text-align:center; padding:4px 0px; text-decoration:none; color:#FFFFFF; font-weight:bold; cursor:pointer; } .caption{ margin:0px auto; width:608px; height:auto; overflow:hidden; padding:1px; background-color:#CCCCCC; } .caption h2{ margin:0px; padding:3px; text-align:center; font-size:12px; background-color:#666666; } .caption ul{ margin:0px; padding:0px 16px; list-style:none; line-height:22px; font-size:12px; } .inputtxt{ width:30px; height:12px; font-size:12px; color:#FF6600; font-weight:bold; text-align:center; } .inputbutton{border:#666666 1px solid;height:18px;} .caption ul a{color:#333333;} .caption ul li{ border-bottom:#666666 1px dashed; } </style> <img src="/_New/_cj/myeditor/sysimage/space.gif" class="ewebeditor__script" _ewebeditor_fake_tag="script" _ewebeditor_fake_value="%3Cscript%20language%3D%22javascript%22%20type%3D%22text%2Fjavascript%22%3E%20%0D%0A%2F*%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%0D%0Acopyright%3Ahttp%3A%2F%2Fwww.wxwdesign.cn%20%0D%0A%E8%BD%AC%E8%BD%BD%E8%AF%B7%E4%BF%9D%E7%95%99%E6%AD%A4%E4%BF%A1%E6%81%AF%E5%92%8C%E4%BD%9C%E8%80%85%E7%BD%91%E7%AB%99%E9%93%BE%E6%8E%A5%20%0D%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D*%2F%20%0D%0Awindow.onload%3Dfunction()%7B%20%0D%0Avar%20n%3D22%3B%20%2F%2F%E9%BB%98%E8%AE%A4%E8%A1%8C%E6%95%B0%20%0D%0Avar%20L%3D23%3B%20%2F%2F%E9%BB%98%E8%AE%A4%E6%AF%8F%E8%A1%8C%E6%98%BE%E7%A4%BA%E4%B8%AA%E6%95%B0%20%0D%0Avar%20acontent%3D%22%2B%22%3B%20%2F%2F%E9%BB%98%E8%AE%A4%E6%96%B9%E6%A0%BC%E9%87%8C%E6%98%BE%E7%A4%BA%E7%9A%84%E7%AC%A6%E5%8F%B7%20%0D%0Avar%20color%3Dnew%20Array(%22%23ea991f%22%2C%22%23cc994b%22%2C%22%23ae9979%22%2C%22%23999999%22)%3B%20%0D%0Avar%20init%3Dfunction(num%2Clen)%7B%20%0D%0Avar%20content%3Ddocument.createDocumentFragment()%3B%20%0D%0Avar%20firstline%3Ddocument.createElement(%22div%22)%3B%20%0D%0Afirstline.className%3D%22line2%22%3B%20%0D%0Afor(var%20i%3D0%3Bi%3Clen%3Bi%2B%2B)%7Bvar%20a%3Ddocument.createElement(%22a%22)%3Ba.innerHTML%3Di%2B1%3Bfirstline.appendChild(a)%7D%20%0D%0Acontent.appendChild(firstline)%3B%20%0D%0Afor(var%20i%3D0%3Bi%3Cnum%3Bi%2B%2B)%7Bvar%20div%3Ddocument.createElement(%22div%22)%3Bdiv.className%3D%22line%22%3Bfor(var%20j%3D0%3Bj%3Clen%3Bj%2B%2B)%7Bvar%20a%3Ddocument.createElement(%22a%22)%3Ba.innerHTML%3Dacontent%3Bdiv.appendChild(a)%3B%7D%3Bcontent.appendChild(div)%3B%7D%20%0D%0Agetid(%22container%22).style.width%3DString(29*len)%2B%22px%22%3B%20%0D%0Agetid(%22caption%22).style.width%3DString(29*len-1)%2B%22px%22%3B%20%0D%0Agetid(%22container%22).appendChild(content)%3B%20%0D%0Avar%20a%3Ddocument.getElementsByTagName(%22a%22)%3B%20%0D%0Afor(var%20i%3D21%3Bi%3Ca.length%3Bi%2B%2B)%7B%20%0D%0Aa%5Bi%5D.onclick%3Dfunction()%7Bif(!this.i)%7Bthis.style.color%3D%22%23ff0000%22%3Bthis.style.backgroundColor%3D%22%23FF9900%22%7Delse%7Bthis.style.color%3D%22%23FFFFFF%22%3Bthis.style.backgroundColor%3D%22%23999999%22%7D%3Bthis.i%3D!this.i%7D%20%0D%0Aa%5Bi%5D.onfocus%3Dfunction()%7Bthis.blur()%7D%20%0D%0Aa%5Bi%5D.onmouseover%3Dfunction()%7Bthis.style.backgroundColor%3D%22%23FF9900%22%7D%20%0D%0Aa%5Bi%5D.onmouseout%3Dfunction()%7Bvar%20obj%3Dthis%3Bvar%20j%3D0%3Bfunction%20dc()%7Bif(j%3Ccolor.length%26%26!obj.i)%7BsetTimeout(dc%2C200)%3Bobj.style.backgroundColor%3Dcolor%5Bj%5D%3Bj%2B%2B%7D%7D%3Bdc()%7D%3B%20%0D%0A%7D%7D%20%0D%0Ainit(n%2CL)%3B%20%0D%0Afunction%20getid(id)%7Breturn%20document.getElementById(id)%7D%20%0D%0Avar%20input%3Ddocument.getElementsByTagName(%22input%22)%3B%20%0D%0Ainput%5B0%5D.onclick%3Dfunction()%7Bwindow.location.reload()%7D%20%0D%0Ainput%5B3%5D.onclick%3Dfunction()%7Bgetid(%22container%22).innerHTML%3D%22%22%3Binit(parseInt(input%5B2%5D.value)%2CparseInt(input%5B1%5D.value))%7D%20%0D%0A%7D%20%0D%0A%3C%2Fscript%3E"> </head> <body> <div class="container" id="container"></div> <div class="caption" id="caption"> <h2>说明</h2> <ul> <li>1.移动鼠标在网页方格里点击,拼出图形。</li> <li>2.如果对某个点不满意,再次点击,即可消除。</li> <li>3.如果想重新开始,请点击这里:<input type="button" value="重新开始" class="inputbutton"/> 或者重新设置:<input type="text" class="inputtxt"/> 列 <input type="text" class="inputtxt" /> 行 <input type="button" value="重新生成" class="inputbutton" /></li> </ul> </div> </body> </html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行
]
教程首页
更多教程