如何在href标签中获得选择框值
How to get select box value in a href tag
如何在php变量的href标签中获得选择框值?
<script type="text/javascript">
$(document).ready(function(){
$("select.id").change(function(){
var selectedid = $(".id option:selected").val();
alert(selectedid);
});
});
</script>
<label>Select Id</label>
<select class="id">
<option value="">SELECT</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="4">5</option>
</select>
<a href="test.php?id=id">Testing</a>
代码如下所示,测试并100%工作,使用jQuery attr
并给hyperlink一个ID,这里的ID是"link":
<a id="link" href="test.php?id=id">Testing</a> <!-- GIVE AN ID, else will affect entire hyperlinks on your project -->
$(document).ready(function(){
$("select.id").change(function(){
var selectedid = $(".id option:selected").val();
$("#link").attr("href","test.php?id="+selectedid); //-----this will change href
});
});
通过使用.attr()
可以改变href
的<a>
标签
change href
on change select option
$(document).ready(function(){
$("select.id").change(function(){
var selectedid = $(".id option:selected").val();
$('a').attr('href','test.php?id='+selectedid);
});
});
工作小提琴:http://jsfiddle.net/ehxj9zrx/
相关文章:
- 当用户在选择框中选择选项时,使用window.location.href重定向用户只会更改导航器中URL的最后一位
- 用于href中元素的jquery选择器
- 如何根据下拉选择更新(追加到其中)href
- 如何选择处于 while 循环中的 href 变量
- 单击 标记时,显示叠加层,如果选择“是”作为选项,则跟随 的 href URL
- 如何根据用户选择的选项更改链接 href(单击)
- 如何使用Selenium Webdriver和Java从href html标签中选择“Page=?” valuse
- 将 HREF 添加到 JQuery 动态填充的选择
- Href 与选择框
- 使用href-jquery动态删除选择选项值
- 更改时选择值更新href链接值
- 如何使用jquery从链接中选择href属性
- 如何制作用href选择的选择框
- JQuery日期选择器-通过href增加日期
- href锚定标记/css选择器问题与canvas类而非id有关
- 自定义Javascript href选择器
- 如何从<选择>中单一值并使用php和javascript分配给href链接
- 将href链接到其他页面选择的下拉选项值
- 刷新选择了相同选项卡href的页面
- 如何从JSON对象中选择href