<body>
<div id="container" style="width:260pxheight:260pxoverflow:hidden"></div>
<script>
var container = document.querySelector("#container")
for(var i=0,a=[]i<25a[i]=i++)
for(var i=0i<25i++){
var div = document.createElement("div")
var len = a.length
var index = Math.floor(Math.random()*len)
index = a.splice(index,1)[0]
(function(i){
div.setAttribute("index",i)
div.innerHTML = parseInt(i)+1
})(index)
div.style.cssText = "width:50pxheight:50pxborder:1px solid blacktext-align:centerline-height:50pxfloat:left"
div.onclick = function(event){
var self = event.target
var index = self.getAttribute("index")
var colored = document.querySelectorAll(".colored")
if(index==colored.length){
self.style.background = "red"
self.className = "colored"
}
if(index==24){
alert("done!")
}
}
container.appendChild(div)
}
</script>
</body>
</html>
用JavaScript:
<script language="javascript"> function replaceReg(reg, str) { return str.replace(reg, function(m) { return arr[m] }) } arr = new Array("零", "一", "二", "三", "四", "五", "六", "七", "八", "九") var reg = /\d/g var str = '3' document.write(replaceReg(reg, str) + '<br />')</script><input type="text" value="1" name=""/><button>点击改变</button>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script>
window.onload=function(){//加载完成后执行
$('button').click(function(){//对button按钮进行监控,监控点击
var val=$('input').val()//获取页面中input的值
val++//input+1
$('input').val(val)//讲改变的值重新写入input
})
}
</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)