我的下拉菜單具有以下onClick功能,select并且button:function functionLooking() { var link = document.getElementById("lookingForThis").value; window.alert(link); location.href(decodeURIComponent(document.getElementById("lookingForThis").value));}<form> <label for="lookingForThis">I'm looking for</label> <select name="lookingForThis" id="lookingForThis" size="1"> <option value="/about/our-congregations.php" data-link="/about/our-congregations.php">a multi-cultural church</option> <option value="/about/our-programs.php" data-link="/about/our-programs.php">a family-oriented church</option> <option value="https://school.faithalaska.com" data-link="https://school.faithalaska.com">a private school</option> <option value="/worship/bible-studies/" data-link="/worship/bible-studies/">a bible study group</option> </select> <button type="submit" onClick="functionLooking()">Let's Find It</button></form>我只有代碼中的警報窗口才能查看值顯示為什么。它對我的功能并不重要,僅用于測試目的。我的問題是,當我單擊按鈕時,警報窗口會根據所選選項的值顯示正確的字符串。例如,選項 1 顯示/about/our-congregations.php。但是,當您單擊確定警報的頁面只是刷新,但附加與選擇元素ID的URL和編碼的URI,像這樣:/?lookingForThis=%2Fabout%2Four-congregations.php。正如您所看到的,我在 Javascript 方面不是很熟練,所以我不知道我做錯了什么。我嘗試過encodeURI,decodeURI最近一次沒有成功。請幫我。
當我單擊 Javascript 中的按鈕時,如何使用存儲在選擇選項值中的 uri?
米琪卡哇伊
2021-08-26 16:35:58