[英]URL share passing parameters
這是我處理這種簡單邏輯的方法:
var sel = document.querySelector("#ddlViewBy"); var input = document.querySelector("input#location"); var button = document.querySelector("button"); var param1 = ''; var param2 = ''; button.addEventListener("click", function(evt){ param1 = sel.options[sel.selectedIndex].value; param2 = input.value; //Just to check the value //alert(param1 + ", " + param2); }); //Then reconstruct your URL bar with the params above /** * orig_url = window.location.href; * window.location.href = orig_url + '?city=' + param1 + '&zip=' + param2 * **/
<select id="ddlViewBy"> <option value="1">test1</option> <option value="2" selected="selected">test2</option> <option value="3">test3</option> </select> <input type="text" id="location" placeholder="Location" /> <button type="button">Submit</button>
我希望這有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.