1.jsԴ?源码源码资本春哥????
2.js for in å for ofçåºå«
3.js的push方法
jsԴ?????
你说的是这种效果吗?<html><head></head>
<body>
<div id="box"></div>
</body>
<script>
(function(){
function Point(x, y, width, color, container)
{
this.instance = null;
this.x = x;
this.y = y;
this.width = width;
this.color = color;
this.click = function()
{
this.instance.click();
}
if(Point.prototype.container == undefined)
{
Point.prototype.container = document.getElementById(container);
}
}
Point.prototype.render = function()
{
var _this = this;
this.instance = document.createElement('button');
this.instance.style.position = "absolute";
this.instance.style.top = this.y;
this.instance.style.left = this.x;
this.instance.style.width = this.width;
this.instance.style.height = this.width;
this.instance.style.backgroundColor = this.color;
this.container.appendChild(this.instance);
this.instance.addEventListener('click', function(){
_this.instance.style.backgroundColor = _this.instance.style.backgroundColor == 'red' ? "blue" : "red" ;
});
}
function Points()
{
var _this = this;
this.container = [];
this.add = function(point)
{
_this.container.push(point);
}
this.run = function()
{
console.log('ssss');
var will_clicked_btns = [];
for(var i = 0; i < 3; i++)
{
will_clicked_btns.push(parseInt(Math.random()*7));
}
for(var i = 0; i < will_clicked_btns.length; i++)
{
_this.container[will_clicked_btns[i]].click();
}
}
}
var points = new Points();
for(var i = 0; i < 8; i++)
{
var x = i * + ;
var p = new Point(x,0,,'red',"box");
p.render();
points.add(p);
}
setInterval(points.run, );
})();
</script>
</html>
js for in å for ofçåºå«
for inæ¯ES5æ åï¼éåkeyï¼å±æ§åï¼ï¼å¹¶ä¸ååé¾ä¸çææå±æ§ä¹ä¼è¢«éåãè¿æ»¤ååé¾ä¸çå±æ§å¯ä»¥ç¨hasOwnProperty()æ¹æ³ãfor inéååä¸è½ä¿è¯é¡ºåºï¼ä¹å°±æ¯é¡ºåºå¯è½ä¼è¢«æä¹±ï¼
for of æ¯ES6æ åï¼éåvalueï¼å±æ§å¼ï¼ï¼è¿ä¸ªæ¹æ³ä¿®å¤for inåå¨ç缺é·ã
js的push方法
For (var n=0;n<;n++)
Info2.push(parseInt(Math.random()*)+1);
//就是插入个1到之间的整数
2024-11-26 01:02
2024-11-26 00:59
2024-11-26 00:57
2024-11-26 00:07
2024-11-25 23:14
2024-11-25 23:11