我的shop.gsp
文件中有以下内容:
<input type="text" class="inputTextBox" name="queryString"/>
<g:link action="shop" controller="item" params='[queryString:
"${document.getElementById('queryString').value}", queryType: "search"]'>
Search
</g:link>
但是在我的控制器中,当我执行一个params.queryString
时,它会返回一个空字符串,我知道我可以为此使用一个表单,但是对于我的问题,我需要像它一样使用这个链接。那么,如何在链接参数中获得输入文本的值呢?
发布于 2014-04-14 20:47:31
下面是一个示例,说明如何使用一些jQuery来实现这一点。从我的头顶上,所以请原谅任何打字。
<input id="field" name="field" type="text" value="" />
<g:link class="mylink" controller="somewhere" action="something">My link</g:link>
<script type="text/javascript">
jQuery(function(){
$("a.mylink").on("click", function(e) {
window.location.href = $(this).attr("href") + "?field=" + $("#field").val();
return false;
});
});
</script>
https://stackoverflow.com/questions/23069345
复制相似问题