質問

I have the following in my shop.gsp file:

<input type="text" class="inputTextBox" name="queryString"/>
<g:link action="shop" controller="item" params='[queryString:
"${document.getElementById('queryString').value}", queryType: "search"]'>
 Search
 </g:link>

But in my controller when I do a params.queryString it returns an empty string.I know I could be using a form for this but for my problem I need to use the link like it is. So how can I get the value of my input text in the link parameters?

役に立ちましたか?

解決

Here is an example of how to do this with the use of some jQuery. Off the top of my head, so please forgive any typos.

<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>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top