我有一个选择框。 我想通过链接作为获取参数来传递其选定的值。 我在选择框的 onchange 事件上使用 JavaScript 获取选择框的值。 现在我怎样才能通过链接?
<script type="text/javascript">
function getArticle(sel){
var value = sel.options[sel.selectedIndex].value;
alert(value);
}
</script>
<a href="edittoc.php?key=value">Edit</a> // how can i do this?
请帮帮我。
最佳答案
这里有几个选项。 jsfiddle: http://jsfiddle.net/a7Rc6/
html:
<a id="one-way">Edit</a>
<a id="another-way" href="#">Edit</a>
JavaScript:
var value = sel.options[sel.selectedIndex].value;
// one way:
document.getElementById('one-way').href = 'edittoc.php?key=' + value;
// another way:
document.getElementById('another-way').onclick = function () {
window.location = 'edittoc.php?key=' + value;
};
关于javascript变量作为获取参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22685992/