页面退出时清除下拉选择框值,解决回退后无法重复选中的实现方案
下拉选择框跳转后返回无法重复触发的解决方案
开发过程中若使用由数据库查询填充的下拉跳转选择框,会存在如下问题:选中选项跳转至其他页面后,点击浏览器返回按钮回到原页面时,此前选中的选项仍会保持选中状态,导致用户无法再次点击该选项跳转,需先切换其他选项才能重新操作。
针对该问题可使用onpopstate函数处理,但下述方案实现更简单,且跨浏览器兼容性更强,可兼容老旧浏览器:
HTML代码
<div> <select class="DropList" name="CitySelect" id="CitySelect" onchange="if(options[selectedIndex].value){location = options[selectedIndex].value}" onclick="GetSelect()"> <option value="" selected>Select City</option> <option value="city.php?s=Montana&cn=Yellowstone&CalNav=0&c=Billings">Billings</option> </select> </div>
JavaScript代码
<script type="text/javascript"> function GetSelect() { document.getElementById('CitySelect').value = ""; } </script>
内容的提问来源于stack exchange,提问作者RationalRabbit
相关产品推荐
相关产品推荐

