对于带有下一个和上一个按钮的文本,我有以下代码。我希望它在页面加载时重复循环,并在两者之间暂停一个按钮。所有三个按钮都完全位于显示文本的同一行的右侧。请支持我。。谢谢。。
<!DOC HTML>
<html>
<head>
<script type="text/javascript">
var messages = [
'Messages for <em>kindergarden</em> class',
'Message for <em>1st grade</em>',
'Message for <em>2nd grade</em>',
'Message for <em>3rd grade</em>',
'Message for <em>4th grade</em>',
'Message for <em>5th grade</em>',
'Message for <em>6th grade</em>'
];
var msgPtr = 0;
function nextMsg(direction) {
msgPtr = msgPtr + direction;
if (msgPtr < 0) { msgPtr = messages.length-1; }
if (msgPtr > messages.length-1) { msgPtr = 0; }
document.getElementById('msg').innerHTML = messages[msgPtr];
}
window.onload = function () {
nextMsg(0);
}
</script>
<style type="text/css">
em { color:orange; }
#msg {
font-family:monospace;
background-color:yellow;
font-size:1em;
width:890px;
border:1px dotted red;
overflow:hidden;}
</style>
</head>
<body>
<div id="msg"></div><br>
<button onclick="nextMsg(-1)"><</button>
<button onclick="nextMsg(-1)">||</button>
<button onclick="nextMsg(1)">></button>
</body>
</html>