gpt4 book ai didi

javascript - 两个带按钮的下拉选项

转载 作者:行者123 更新时间:2023-12-03 05:48:59 26 4
gpt4 key购买 nike

我正在努力完成这项工作。

我有 2 个下拉列表。一旦用户选择所需的值并单击按钮。该按钮将根据两个下拉列表中所选的选项加载特定的 URL。

https://jsfiddle.net/vs3q879c/

<script>
$(document).ready(function() {

OR = document.getElementById("orientation");
SZ = document.getElementById("size");
ORSZ = OR + SZ;




switch (ORSZ) {
case PA5:
window.location.href = "www.xxxx.wwww/one.html";
break;

case PA4:
window.location.href = "www.xxxx.wwww/two.html";
break;

case PA3:
window.location.href = "www.xxxx.wwww/three.html";
break;

case LA5:
window.location.href = "www.xxxx.wwww/four.html";
break;

case LA4:
window.location.href = "www.xxxx.wwww/five.html";
break;

case LA3:
window.location.href = "www.xxxx.wwww/six.html";
break;

default:
default none();
}

</script>

最佳答案

你有一些错误。不要使用 window.location.href,而是尝试使用 window.open("www.my-url.com")

此外,您的 switch 子句 中有 2 个默认语句,请尝试如下操作:

switch (ORSZ) {
case PA5:
window.location.href = "www.xxxx.wwww/one.html";
break;

case PA4:
window.location.href = "www.xxxx.wwww/two.html";
break;

case PA3:
window.location.href = "www.xxxx.wwww/three.html";
break;

case LA5:
window.location.href = "www.xxxx.wwww/four.html";
break;

case LA4:
window.location.href = "www.xxxx.wwww/five.html";
break;

case LA3:
window.location.href = "www.xxxx.wwww/six.html";
break;

default: none();
}

最后,当您通过 ID 获取选择元素时,您获取的是对象而不是所选值。要解决这个问题,您需要使用 .value:

OR = document.getElementById("orientation").value;
SZ = document.getElementById("size").value;
ORSZ = OR + SZ;

演示:http://jsbin.com/tivocodeza/edit?html,js,output

关于javascript - 两个带按钮的下拉选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40222888/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com