如何使用Javascript在浏览器的"后退"按钮上重置(返回0索引)下拉列表?
您可以使用'onbeforeunload'事件:
<script>
function reset_options() {
document.getElementById('MySelect').options.length = 0;
return true;
}
</script>
<body onbeforeunload='reset_options()'>
...
Run Code Online (Sandbox Code Playgroud)
小智 5
是的很容易.
我有一个Dropbox,它的id是"stroke_style",重置只是将它设置为-1索引(在0之前)
document.getElementById("stroke_style").selectedIndex = -1;
Run Code Online (Sandbox Code Playgroud)
示例:http://languagelassi.blogspot.in/search/label/Dropdown%20Reset%20Javascript
并且您可以将其放在方法中或直接放在<body onload="">该页面中
<script type="text/javascript" language="javascript" >
var orig_default = -1;
function setDefault() {
if (orig_default < 0) {orig_default = document.getElementById("MyList").selectedIndex;}
}
function testReset() {
if (orig_default >= 0) {
document.getElementById("MyList").selectedIndex = orig_default;
}
}
</script>
<body onbeforeunload='setDefault();'>
Run Code Online (Sandbox Code Playgroud)
以下是我自己编写的几个脚本,用于解决单击浏览器后退按钮时重置 html 值的问题。