最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js 隨機數代碼大全

 更新時間:2010年08月20日 15:26:51   作者:  
很多情況下,需要用到隨機數,腳本之家特為大家整理了一些具體的使用與說明。



引用部分:

1. 從1開始 至 任意值
parseInt(Math.random()*上限+1);

2. 從任意值開始 至 任意值
parseInt(Math.random()*(上限-下限+1)+下限);
function fRandomBy(under, over){
switch(arguments.length){
case 1: return parseInt(Math.random()*under+1);
case 2: return parseInt(Math.random()*(over-under+1) + under);
default: return 0;
}
}
document.write(fRandomBy(1,100));  //輸出指定范圍內的隨機數的隨機整數
</script>

下面是給文本框按規(guī)則付不同的隨即值[引申]
復制代碼 代碼如下:

1-10: <input type="text" /><br />
11-20: <input type="text" /><br />
1-100: <input type="text" /><br />
51-100: <input type="text" /><br />

<script>
window.onload=function(){
var o=document.getElementsByTagName('input');
o[0].value=fRandomBy(1,10);
o[1].value=fRandomBy(11,20);
o[2].value=fRandomBy(1,100);
o[3].value=fRandomBy(51,100);
}
</script>


[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]

相關文章

最新評論

芒康县| 电白县| 高安市| 鹤山市| 汽车| 上思县| 昌都县| 松原市| 同德县| 桦甸市| 松原市| 南皮县| 德令哈市| 兰西县| 沅陵县| 邹城市| 临清市| 蕲春县| 石景山区| 怀来县| 安陆市| 烟台市| 隆子县| 庄河市| 茶陵县| 马山县| 旬阳县| 天祝| 永吉县| 饶阳县| 朝阳县| 长海县| 车险| 航空| 巨野县| 盖州市| 北辰区| 大余县| 江源县| 兴安县| 昭苏县|