如何链接category <option>标签

时间:2016-06-28 09:13:40

标签: javascript html css wordpress wordpress-plugin

我想将类别链接到他们自己的页面。所以我的意思是当我点击“&#39; Hotels&#39;它应该打开Category / Hotels

页面

enter image description here

这是当前的代码

<select name="category">
  <option value="">Any Category</option>
  <option value="clubs">Clubs</option></a>
  <option value="hotels">Hotels</option>
  <option value="pubbar">Pub&amp;Bar</option>
  <option value="restaurants">Restaurants</option>
</select>

假设我想像那样链接

  <option value="www.website.com/event_cat/clubs/> Clubs </option>
  <option value="www.website.com/event_cat/hotels/> Hotels </option>
.. and so on

但是当我这样做时,它指向这个页面:

www.website.com/events/?time=&category=%2Fevent_cat%2Fclubs%2F&location=

3 个答案:

答案 0 :(得分:1)

JSfiddle Demo

 <html>
    <body>
      <form name="blah_blah">
        <select name="ddmenu_name" id="ddmenu_name" style="width: 80% !important;">
          <option value="" selected>Select Site</option>
          <option value="http://www.yahoo.com">Yahoo!!!</option>
          <option value="http://www.gmail.com">Gmail</option>
          <option value="http://www.google.co.in">Google</option>
          <option value="http://www.facebook.com">Facebook</option>
        </select>
        <input type="button" name="Submit" value="Go!" onClick="window.open(ddmenu_name.value,'newtab'+ddmenu_name.value)">
      </form>
    </body>
 </html>

答案 1 :(得分:1)

您只需使用 http或https(如果是安全服务器)的完整域路径

 <option value="http://www.website.com/event_cat/clubs/> Clubs </option>
 <option value="http://www.website.com/event_cat/hotels/> Hotels </option>

答案 2 :(得分:0)

由于您已经选择了第一个选项,因此在第一个选项中,将值保持为空并添加onchange,如下面的代码所示:

<select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
  <option value="">Any Category</option>
  <option value="www.website.com/event_cat/clubs/">Clubs</option>
  <option value="www.website.com/event_cat/hotels/">Hotels</option>
  <option value="pubbar">Pub&amp;Bar</option>
  <option value="restaurants">Restaurants</option>
</select>