[英]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.