jquery 使用 select 中的值更改 attr href
我有这样的形式:
<div id="select_1">
<select class="select-class">
<option value="value_1" selected="selected">1</option>
<option value="value_2">2</option>
<option value="value_3">3</option>
</select>
<a href="#" class="a-class">Link</a>
</div>
<div id="select_2">
<select class="select-class">
<option value="value_1">1</option>
<option value="value_2" selected="selected">2</option>
<option value="value_3">3</option>
</select>
<a href="#" class="a-class">Link</a>
</div>
<div id="select_3">
<select class="select-class">
<option value="value_1" selected="selected">1</option>
<option value="value_2">2</option>
<option value="value_3">3</option>
</select>
<a href="#" class="a-class">Link</a>
</div>
对于选择项目的每一行,我想用这个值更改 attr href : href="url.com?"+ 从 select 中选择的选项值
我如何使用 jquery 执行此操作?
谢谢
I have this form :
<div id="select_1">
<select class="select-class">
<option value="value_1" selected="selected">1</option>
<option value="value_2">2</option>
<option value="value_3">3</option>
</select>
<a href="#" class="a-class">Link</a>
</div>
<div id="select_2">
<select class="select-class">
<option value="value_1">1</option>
<option value="value_2" selected="selected">2</option>
<option value="value_3">3</option>
</select>
<a href="#" class="a-class">Link</a>
</div>
<div id="select_3">
<select class="select-class">
<option value="value_1" selected="selected">1</option>
<option value="value_2">2</option>
<option value="value_3">3</option>
</select>
<a href="#" class="a-class">Link</a>
</div>
For each line of select item, I want to change attr href with this value :
href="url.com?"+ value of option selected from select
How can i do this with jquery ?
Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我假设当用户从 select 元素之一选择一个选项时,相邻的 a 元素应该更新,我对你的理解是否正确?在这种情况下:
您也可能希望在浏览器中加载文档时更新所有 a 元素。在这种情况下:
Am I understanding you correctly if I assume that, when the user selects an option from one of the select elements, the adjacent a element should be updated? In that case:
It could also be that you want to update all a elements when the document is loaded in the browser. In that case:
您只需在更改 select 的值后更改 a 标记的
href attr
即可。您可以在此处尝试工作代码,它设置href
属性每次选择框的值更改时都会更改链接。you can simply change the
href attr
of the a tag after the value of the select is changed. You can try the working code here, it sets thehref
attribute of the link every time the value of the select box is changed.