从javascript写入div
我试图创建一个div框,其中显示javascript中生成的随机引用,但在运行代码时不会显示 我的html很简单从javascript写入div,javascript,html,Javascript,Html,我试图创建一个div框,其中显示javascript中生成的随机引用,但在运行代码时不会显示 我的html很简单 <div id="quotebox"></div> 我只是犯了一个愚蠢的错误还是怎么了?我现在尝试了几种不同的方法,但它仍然不会显示在div中。请确保您有一个id为“quotebox”的元素(div、td,无论什么): 函数showQuote(){ var quotes=新数组() quotes[0]=“简洁是终极的精神支柱”; 引用[1]=“当我以为我在
<div id="quotebox"></div>
我只是犯了一个愚蠢的错误还是怎么了?我现在尝试了几种不同的方法,但它仍然不会显示在div中。请确保您有一个id为“quotebox”的元素(div、td,无论什么):
函数showQuote(){
var quotes=新数组()
quotes[0]=“简洁是终极的精神支柱”;
引用[1]=“当我以为我在学习如何生活时,我却在学习如何死亡。”;
引用[2]=“人们遭受的最大欺骗来自他们自己的观点。”;
quotes[3]=“艺术永远不会结束,只有放弃”;
引用[4]=“铁因废弃而生锈;水因停滞而失去纯净。即使如此,不作为也会削弱心灵的活力。”;
var randQuote=Math.floor(Math.random()*(quotes.length));
document.getElementById(“quotebox”).innerHTML=quotes[randQuote];
}
window.onload=function(){
var quotes=新数组()
quotes[0]=“简洁是终极的精神支柱”;
引用[1]=“当我以为我在学习如何生活时,我却在学习如何死亡。”;
引用[2]=“人们遭受的最大欺骗来自他们自己的观点。”;
quotes[3]=“艺术永远不会结束,只有放弃”;
引用[4]=“铁因废弃而生锈;水因停滞而失去纯净。即使如此,不作为也会削弱心灵的活力。”;
var randQuote=Math.floor(Math.random()*(quotes.length));
document.getElementById(“quotebox”).innerHTML=quotes[randQuote];
};
您没有调用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()
在此处插入标题
var quotes=新数组()
quotes[0]=“简洁是终极的精神支柱”;
引用[1]=“当我以为我在学习如何生活时,我却在学习如何死亡。”;
引用[2]=“人们遭受的最大欺骗来自他们自己的观点。”;
quotes[3]=“艺术永远不会结束,只有放弃”;
引用[4]=“铁因废弃而生锈;水因停滞而失去纯净。即使如此,不作为也会削弱心灵的活力。”;
var randQuote=Math.floor(Math.random()*(quotes.length));
函数showQuote(){
document.getElementById(“quotebox”).innerHTML=quotes[randQuote];
}
这段代码在我的浏览器上运行良好。您的浏览器可能有问题。是否在任何地方调用showQuote()?或者尝试检查引号变量以确保其中包含数据。我尝试在和中调用它,但没有任何结果。检查引号变量是什么意思?div中仍然没有显示任何内容。上面的代码工作正常:)检查更新!使用window.onload()这条评论是干什么的?我把它删除了..被错误地贴在这里了。谢谢通知
function showQuote(){
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));
document.getElementById("quotebox").innerHTML = quotes[randQuote];
}
</script>
<body onload="showQuote();">
<div id="quotebox">
</div>
</body>
<script>
window.onload=function(){
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));
document.getElementById("quotebox").innerHTML = quotes[randQuote];
};
</script>
<body >
<div id="quotebox"></div>
</body>
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()
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<script>
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];
}
</script>
<body onload="showQuote()">
<div id="quotebox"></div>
</body>
</html>