我的下拉菜单具有以下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最近一次没有成功。请帮我。
相关分类