简体   繁体   English

将选择框值附加到href

[英]appending select-box value to href

I have a select box with few options. 我有一个带有几个选项的选择框。 eg 例如

<select>
   <option value="India">India</option>
   <option value="Usa">Usa</option>
  </select>

I have href element as below and i want the value of selected option in select box to be appended to the href link, while clicking the href element. 我具有href元素,如下所示,我希望在单击href元素的同时将选择框中的selected选项的值附加到href链接。 lets say name=India. 假设name = India。

eg <a href="http://localhost:8080/country?name=">Visit Country</a> 例如<a href="http://localhost:8080/country?name=">Visit Country</a>

$('select').on('change', function() {
    var old_href = $('a').attr('href'),
        new_href = old_href.split('=')[0] + '=' + this.value;
    $('a').attr('href', new_href);
});

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

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