[英]index not reset to 0 after i get back to the page by the back key
Following is the script that makes a jump menu.Using javascript i have set the index of the options
tag to be equal to 0.The scrip works fine except one.After i jump to another page from the jump menu the index is not reset to the index 0.Instead it is set to the index where i had clicked.Why is it so ? 以下是制作跳转菜单的脚本。使用javascript,我将
options
标签的索引设置为等于0.除了一个以外,该脚本均正常运行。从跳转菜单跳转到另一页后,索引未重置为索引0.相反,它设置为我单击过的索引。为什么这样? What is the problem with script ? 脚本有什么问题?
script: 脚本:
window.onload = startInit;
function startInit() {
document.getElementById("newLocation").selectedIndex = 0;
document.getElementById("newLocation").onchange = jumpPage;
}
function jumpPage() {
var newLoc = document.getElementById("newLocation");
var newPage = newLoc.options[newLoc.selectedIndex].value;
if(newPage != "")
window.location = newPage;
}
HTML 的HTML
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="script.js">
</script>
</head>
<body bgcolor="#FFFFCC">
<center>
<form>
<select id="newLocation">
<option value="myworld.gif">first</option>
<option value="myhome.gif">second</option>
<option value="myroom.gif">third</option>
<option value="mybed.jpg">fourth</option>
</select>
</form>
Browser acts smart and caches your page. 浏览器行为聪明,并缓存您的页面。 So are seeing the cached version of your HTML page.To ensure that this doesn't happen and you always start up with the 0th index,tell the browser not to do anything (the way you want) when the page unloads.
因此,请参见HTML页面的缓存版本。为确保不会发生这种情况,并始终使用0th索引启动,请告诉浏览器在页面卸载时不执行任何操作(您想要的方式) 。
The statement should be: window.onunload = function(){}; // do nothing function
该语句应为:
window.onunload = function(){}; // do nothing function
window.onunload = function(){}; // do nothing function
you can add after window.onload = startInit;
您可以在
window.onload = startInit;
之后添加window.onload = startInit;
That tells the browser that something happened during unloading and therefore it should re-read the page. 这告诉浏览器卸载过程中发生了某些事情,因此应该重新读取页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.