从javascript写入div
16lz
2021-01-22
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()
更多相关文章
- 寻找解决方案,以每100速率1显示div随机而不创建其他div
- 等待执行所有ajax回调的最佳解决方案
- 【问题解决方案】ImportError: No module named 'pygal'
- Python 黏包及黏包解决方案
- 无法安装ndg-httpsclient或者我的解决方案错误
- Linux无法连接网络解决方案
- Media-S 简介(一个开源的DRM解决方案)
- AppScan安全问题解决方案
- PLSQL乱码解决方案