我想做一个属于自己的速读软件。为此,我需要文本不断变化并在段落结束时停止。我尝试了一些内容包含在任何数组中并且文本不断完美变化但它不会停止并连续旋转数组内容的东西。我希望在数组结束时停止文本。请帮助我!!!!
这是我的代码,
<html>
<head>
<title>Replacing Text</title>
<script language="JavaScript">
var msgIX = 0
var msgs = new Array(
"Notice anything different?",
"The text you are looking at has changed.",
"This is a handy way of sending messages to your users."
)
function scrollMessages(milliseconds) {
window.setInterval("displayMessage()", milliseconds)
}
function displayMessage() {
if(document.getElementById != null) {
var heading = document.getElementById("scrollme")
heading.firstChild.nodeValue = msgs[msgIX]
}else{
if(navigator.appName == "Microsoft Internet Explorer") {
var heading = document.all.item("scrollme")
heading.innerText = msgs[msgIX]
}
}
++msgIX
msgIX %= msgs.length
}
</script>
</head>
<body onload="scrollMessages(2000)">
<h1 align="center" id="scrollme">Watch this text very carefully!</h1>
</body>
</html>
最佳答案
试试这个
<html>
<head>
<title>Replacing Text</title>
<script language="JavaScript">
var msgIX = 0
var msgs = new Array(
"Notice anything different?",
"The text you are looking at has changed.",
"This is a handy way of sending messages to your users."
)
function displayMessage(milliseconds) {
if(msgIX < msgs.length){
if(document.getElementById != null) {
var heading = document.getElementById("scrollme")
heading.firstChild.nodeValue = msgs[msgIX]
}else{
if(navigator.appName == "Microsoft Internet Explorer") {
var heading = document.all.item("scrollme")
heading.innerText = msgs[msgIX]
}
}
++msgIX;
window.setTimeout(function(){displayMessage(milliseconds);},milliseconds);
}
}
</script>
</head>
<body onload=" window.setTimeout(function(){displayMessage(5000);},5000);">
<h1 align="center" id="scrollme">Watch this text very carefully!</h1>
</body>
</html>
关于javascript - 定期更新 HTML 元素显示的文本并在内容数组结束时停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21521605/