简体   繁体   English

选择选项onchange时在锚标记中显示值

[英]Show value in anchor tag when select option onchange

Below is script when select option onchange input box will echo the value for select option : 以下是当select选项的onchange输入框将回显select选项的值时的脚本:

<select id="theSelect">
 <option value="888">Foo</option>
 <option value="999">Bar</option>
</select>
<br />
<input id="someInput"/>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script>
  $("#theSelect").change(function() {
  $("#someInput").val($(this).val());
  }).change(); // trigger once if needed
</script>

My question is how to echo value inside the Anchor Tag(refer id value) : 我的问题是如何在锚标记内回显值(请参阅id值):

example : <a href="index.php?id=999" id="link">Click here</a> 示例: <a href="index.php?id=999" id="link">Click here</a>

thanks. 谢谢。

You can use prop() method to set href value for the link: 您可以使用prop()方法来设置链接的href值:

$("#theSelect").on("change", function() {
    $("#link").prop("href", "index.php?id=" + this.value);
});

Try this 尝试这个

$(function() {
    $('#theSelect').on('change' , function() {
        var $anchor = $('#link')
        var currVal = $(this).find('option:selected').val();
        alert('Old href is : ' + $anchor.attr('href'));
        $anchor.attr('href' , 'index.php?id=' + currVal);
        alert('New href is : ' + $anchor.attr('href'));

    })
});​

Check DEMO 检查演示

暂无
暂无

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

相关问题 当选择列表选项随onchange更改时尝试显示一个值 - Trying to display a value when the select list option changes with onchange 如何从中检索循环值属性 <option>标记并传递到中的onchange属性<select>标签 - How to retrieve looped value attributes from <option> tag and pass to the onchange attribute in <select> tag 如何使用jQuery数据表的onChange事件从html select标签选项值中获取值? - How to get value from html select tag option value using onChange event using jQuery data table? 根据选项选择具有值的onchange调用方法 - Select onchange calls method with value depending on option 选择onchange获取选项名称属性值 - select onchange get option name attribute value 如果选项值为“ True”,则选择List onChange不起作用 - Select List onChange not working if the option value is “True” onchange函数,用于在有单个选项时进行选择 - onchange function for select when there is a single option 当 select 选项改变 (onChange) 时,react-select 清除其他输入字段的值(状态) - React-select clears the value (state) of the other input fields when select option is changed (onChange) 使用带有OnChange功能的Tag选项选择外部CSS - Select external CSS using tag Option with OnChange function 当从json的其他选择标记中选择了特定选项时,在选择标记中显示选项 - show options in select tag when a specific option is selected in other select tag from json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM