[英]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. 谢谢。
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'));
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.