JS选择页面刷新中的随机报价 [英] JS Pick Random Quotes on Page Refresh

查看:38
本文介绍了JS选择页面刷新中的随机报价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立自己的网站,我想要它,以便每次用户刷新页面时,都会弹出一个新的随机笑话,而不是以前选择的那个笑话.这是我现在拥有的脚本:

I'm making my website and I want it so that every time the user refreshes the page, a new random joke pops up instead of the previously picked one. This is the script I have right now:

function ShowJoke(){
  var Joke=["Jokes", "go", "here"];
  var Pick = Math.floor(Math.random() * (Joke.length));
  document.write(Joke[Pick]);
}

推荐答案

您的代码看起来不错.但是,您有语法错误.另外,您没有调用功能

Your code looks fine. But, you have syntax errors. Also, you are not calling the finction

function ShowJoke()
  {
    var Joke = [
    	'Joke1',
    	'Joke2',
    	'Joke3',
    	'Joke4',
    	'Joke5',
    	'Joke6'
    ];
    var Pick = Math.floor(Math.random() * (Joke.length));
    document.write(Joke[Pick]);
  }
  
  document.addEventListener("load", ShowJoke());

这篇关于JS选择页面刷新中的随机报价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆