点击按钮选择选项网址

时间:2016-09-29 00:07:34

标签: jquery url hide

我有一个选择输入类型,其中我有许多URL值选项。我还有一个按钮,显示是否选择了任何选项。但是如果我选择并选择并按下按钮需要一种方法它应该带我到那个URL。我不擅长JS。这就是我做的。感谢

<form class="center" name="jump">
  <select name="menu">
    <option value="">States</option>
    <option value="https://siteurl.com/product/alabama/">Alabama</option>
    <option value="https://siteurl.com/product/alaska-advance-directive-for-health-care/">Alaska</option>
    <option value="https://siteurl.com/product/arizona-advance-directive-for-health-care/">Arizona</option>
    <option value="https://siteurl.com/product/arkansas-advance-directive-for-health-care/">Arkansas</option>
    <option value="https://siteurl.com/product/california-advance-directive-for-health-care/">California</option>
    <option value="https://siteurl.com/product/colorado-advance-directive-for-health-care/">Colorado</option>
  </select>
  <br>

  <input class="box" type="button" style="display: inline-block;">

</form>

<script type="text/javascript">
$(document).ready(function(){

   $("select").change(function(){
        $(this).find("option:selected").each(function(){
        if($(this).attr("value")==""){

                $(".box").hide();
            }
            else{
                $(".box").show();
      $('.box').on('click', function () {
          var url = $(this).attr("value"); 
          if (url) { 
              window.location = url; 
          }
          return false;
      });

            }
        });
    }).change();
});



</script>

1 个答案:

答案 0 :(得分:0)

尝试

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<button>Add</button>

<div>
  <ul>
  </ul>
</div>

我认为可以查看此链接here