简体   繁体   English

两个带按钮的下拉选项

[英]Two Drop Down options with a button

I am trying to get this work. 我正在努力进行这项工作。

I have 2 dropdown lists. 我有2个下拉列表。 Once the user select the required value and click the button. 用户选择所需的值后,单击按钮。 The button will load specific URL based on the selected options in both the dropdowns. 该按钮将基于两个下拉列表中的所选选项加载特定的URL。

https://jsfiddle.net/vs3q879c/ 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>

You have a few mistakes. 你有一些错误。 Instead of using window.location.href , try using window.open("www.my-url.com") . 代替使用window.location.href ,请尝试使用window.open("www.my-url.com")

Also, you have 2 default statements in your switch clause , try something like this: 另外,您在switch clause有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();
}

Lastly, when you're getting the select elements by ID, you're grabbing the object instead of the selected value. 最后,当您通过ID获取选择元素时,您将获取对象而不是所选值。 To fix that, you need to use .value : 要解决此问题,您需要使用.value

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

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

Yeah, the above - grab the value of the input, not the element. 是的,上面-抓住了输入的值,而不是元素。

You are also using jQuery in your fiddle $(document).ready(); 您还在提琴$(document).ready();使用jQuery $(document).ready();

if you are doing that, you can use jQuery for everything. 如果这样做,则可以使用jQuery进行所有操作。 Not sure you want that but in case you do, here is a code suggestion: 不确定您是否想要这样做,但是如果您这样做,可以参考以下代码:

$(document).ready(function() {
  $('#submit').click(function(e) {
    e.preventDefault();
    var ORSZ = $('#orientation').val() + $('size').val();

    switch (ORSZ) {
      case PA5:
      window.open("www.xxxx.wwww/one.html", '_blank');
    break;

    //e
    //t
    //c

  });
});

I added the id="submit" to your button to make it easier to select. 我将id="submit"到您的按钮中,以使其更易于选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM