javascript实现随机读取数组的方法

时间:2015-08-03    点击:82   

本文实例讲述了javascript实现随机读取数组的方法。分享给大家供大家参考。具体如下:

function write_quote() {
  var quotes = [
    'no animals were harmed while making this page',
    'made in ulm',
    'this page was handmade',
    'Get <a href="http://www.mozilla.org/products/firefox/">FireFox</a> :-)'
  ];
  var r = Math.round(Math.random() * (quotes.length-1));
  // write the quote
  document.write(quotes[r]);
  // or replace an HTML element:
  // document.getElementById("quote").innerHTML = quotes[r];
}

希望本文所述对大家的javascript程序设计有所帮助。

网页收藏夹显示ICO图标(代码少)
函数window.open实现关闭所有的子窗口
javascript常见数据验证插件大全
javascript自定义in_array()函数实现方法
JavaScript简单修改窗口大小的方法
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved