[英]Passing parameters on onChange of html select
可以说我有两个HTML页面,它们都包含相同的选择框:
<select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
<option value="/site1.php">Site1</option>
<option value="/site2.php">Site2</option>
</select>
我正在寻找一种将selectedIndex的值传递到下一页的方法,因此我也可以在第二页的选择框使用它。 有什么建议么?
提前致谢
localStorage的
商店:
localStorage.userEdits=this.options[this.selectedIndex].value;
在另一页上获取:
var yourIndex = localStorage.userEdits;
哈希
组:
window.location.href="yourURL#index="+this.options[this.selectedIndex].value;
得到:
var yourIndex=window.location.hash.replace("index=","").parseInt();
您可以使用查询参数:
window.location = 'YOUR_URL?selectedIndex=' + this.options[this.selectedIndex].value
使用查询参数会强制您解析它们。 这说明在这里 (你可以做纯JS罚款)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.