I'm trying to make a div box where it displays a randomized quote generated in the javascript, but it does not display when I run the code.

我正在尝试创建一个div框,它显示在javascript中生成的随机引用,但是当我运行代码时它不会显示。

My html is simply

我的HTML很简单

<div id="quotebox"></div>

my javascript is

我的javascript是

var quotes = new Array()
quotes[0]="Simplicity is the ultimate sopistication";
quotes[1]="While I thought that I was learning how to live, I have been learning how to die.";
quotes[2]="The greatest deception men suffer is from their own opinions.";
quotes[3]="Art is never finished, only abandoned";
quotes[4]="Iron rusts from disuse; water loses its purity from stagnation. Even so does inaction sap the vigor of the mind.";

var randQuote=Math.floor(Math.random()*(quotes.length));
function showQuote(){
    document.getElementById("quotebox").innerHTML = quotes[randQuote];
}

Am I just making a silly mistake or what is going on? I've tried several different things now and it still doesn't display to the div.

我只是犯了一个愚蠢的错误或者发生了什么?我现在尝试了几种不同的东西,它仍然没有显示给div。

4 个解决方案

#1


1

You are not calling showQuote(); Here is the working JS fiddle http://jsfiddle.net/9bmAN/

你没有调用showQuote();这是工作的JS小提琴http://jsfiddle.net/9bmAN/

var quotes = new Array()
quotes[0]="Simplicity is the ultimate sopistication";
quotes[1]="While I thought that I was learning how to live, I have been learning how to die.";
quotes[2]="The greatest deception men suffer is from their own opinions.";
quotes[3]="Art is never finished, only abandoned";
quotes[4]="Iron rusts from disuse; water loses its purity from stagnation. Even so does inaction sap the vigor of the mind.";

var randQuote=Math.floor(Math.random()*(quotes.length));
function showQuote(){
    document.getElementById("quotebox").innerHTML = quotes[randQuote];
}

showQuote()

更多相关文章

  1. 寻找解决方案,以每100速率1显示div随机而不创建其他div
  2. 等待执行所有ajax回调的最佳解决方案
  3. 【问题解决方案】ImportError: No module named 'pygal'
  4. Python 黏包及黏包解决方案
  5. 无法安装ndg-httpsclient或者我的解决方案错误
  6. Linux无法连接网络解决方案
  7. Media-S 简介(一个开源的DRM解决方案)
  8. AppScan安全问题解决方案
  9. PLSQL乱码解决方案

随机推荐

  1. C#使用AForge实现摄像头录像功能的案例
  2. .Net Core之实现下载文件的实例
  3. c#之浮点数计算问题的解决
  4. C#单例模式的实现以及性能对比的实例
  5. C#之FastSocket实战项目的示例分享
  6. .NET支付宝App支付接入的实例分析
  7. C#根据表格偶数与奇数加载不同颜色的实例
  8. C#中关于程序功能实现以及对代码选择的思
  9. 介绍asp.net MVC下使用rest的方法
  10. C#中的抽象类与接口的详解