# js产生完全不相同的随机数组，text新用法

2015/06/16 11:24

1.判断在页面是鼠标的click事件还是手机移动端的tap事件

var _click = "ontouchend" in document ? "tap" : "click";
2.产生随机数组
Math.RandomNumbers = function (rn, rcount, bn, bcount) {
var ret = [];
var re = [];
for (var i = 0; i < rcount; i++) {
ret[i] = Math.ceil(Math.random()*(rn-1)+1);
for (var n = 0; n < i; n++) {
if (ret[i] == ret[n]) {
ret[i] = Math.ceil(Math.random()*(rn-1)+1);
n= -1;
};
};
var type = typeof ret[i];
ret[i] = ret[i]<10 && type!='string'?'0'+ret[i]:ret[i];
}
for (var i = 0; i < bcount; i++) {
re[i] = Math.ceil(Math.random()*(bn-1)+1);
for (var n = 0; n < i; n++) {
if (re[i] == re[n]) {
re[i] = Math.ceil(Math.random()*(bn-1)+1);
n= -1;
};
};
var type = typeof re[i];
ret.push(re[i]<10 && type!='string'?'0'+re[i]:re[i]);
};
return ret;
}

3.text(n,current)    n是索引值，current是里面的文本值

$("#dtBall li").each(function(index, el) {$(this).find('em').text(function(n, curText){
curText = deBall[index][n];
return curText;
})
\$(this).find('strong').text(deBall[index][6]);
});

0
6 收藏

0 评论
6 收藏
0