2014-03-25 68 views

回答

0

您可以使用下面的代码,以显示下拉值:

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>Sample title</title> 
    <script> 
    function getValue(value) 
    { 
    alert(value); 
    document.getElementById("test").style.display = "inline"; 
    document.getElementById("test").innerHTML = value; 

    // $("#test").html(value); 

    } 
</script> 
</head> 
<body> 
    <h1>Sample line</h1> 
    <g:select id="plantselect" 
     name="plant" from="${plantList.list()}" 
     optionKey="id" optionValue="id" onchange="getValue(this.value)"/> 
<!-- if you want to other field than id then change id to that field.--> 
    <br/> 

    <div id="test" style="display: none"> 
    </div> 
</body> 

</html> 
0

你应该是选择的ID通过简单地在您的gsp形式控制器如果另一个域值,然后利用

访问

domain.thislistdomain.id在JSP Student.course.id或选择,并通过该ID的G值一定的价值:选择

:)

或GSP本身,你可以做到以下几点:

<g:javascript> 
    $("gselectidhere").change(function() { 
     alert("You selected"+this.val()); 
     //if you want to process and communicate at selection with the controller please add ajax post or get call here ... 
    }); 

</g:javascript> 

//或者你可以忧色G:远程标签和请参考这里:

Grails remotefunction to populate dropdownlist with Jquery

+0

我想在将选定的值传递给gsp本身的控制器 – user3444431

+0

之前进行检查吗? – danielad

+0

嗨,我试图检查选择的值,并做一个如果其他!所以它基本上在同一页面上。假设我想更改标签名称,如果选择的值是x ... – user3444431

0

当然,试试这个:

<g:select id="plaintselect" name="plant.id" from="${Plant.list()}" optionKey="id" required="" value="${plant?.id}" class="many-to-one"/> 

别忘了重写toString() in Plant class,cos这个值被defolt用来为选择建立optionValue。

更多信息要显示在下拉列表在同普惠制的选择值

相关问题