2014-03-25 117 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。

更多信息要顯示在下拉列表在同普惠制的選擇值

相關問題