也许我的问题很琐碎,但我找不到答案。也许我在显示器前已经走了很多个小时:)
我有这种情况:
<div class="col-xs-3" style='margin-left: -50px;'>
<a class="btn btn-primary" href="?c=Student&a=list" id="protokol"> List Studens</a>
</div>
它代表一个按钮,并带有单击事件,使用MVC调用控制器
Student
并执行功能list
。但是我需要向该函数发送一个参数,该参数是HTML组件的值。<input type='text' id='parm' value=''>
我如何使用相同的结构来做到这一点?我尝试了这个,但不正确
<div class="col-xs-3" style='margin-left: -50px;'>
<a class="btn btn-primary" href="?c=Student&a=list&v=<script>$('param').val();</script>" id="protokol"> List Studens</a>
</div>
最佳答案
如果您使用的是jQuery,则可以将单击处理程序附加到该元素上,该元素将附加input
的当前值。尝试这个:
$(function() {
$('#protokol').click(function(e) {
e.preventDefault(); // prevent the browser going to the default URL
var url = $(this).attr('href') + '&v=' + $('#param').val();
window.location.assign(url);
});
});