如何在gsp上顯示下拉列表的選定值?如何顯示gsp上的下拉列表的選定值
<g:select id="plantselect"
name="plant" from="${plantList.list()}"
value="${plant.id}" />
難道我不能像$ {plant}那樣來顯示選定的值嗎?
如何在gsp上顯示下拉列表的選定值?如何顯示gsp上的下拉列表的選定值
<g:select id="plantselect"
name="plant" from="${plantList.list()}"
value="${plant.id}" />
難道我不能像$ {plant}那樣來顯示選定的值嗎?
您可以使用下面的代碼,以顯示下拉值:
<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>
你應該是選擇的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:遠程標籤和請參考這裏:
我想在將選定的值傳遞給gsp本身的控制器 – user3444431
之前進行檢查嗎? – danielad
嗨,我試圖檢查選擇的值,並做一個如果其他!所以它基本上在同一頁面上。假設我想更改標籤名稱,如果選擇的值是x ... – user3444431
當然,試試這個:
<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。
更多信息要顯示在下拉列表在同普惠制的選擇值
確實看到http://grails.org/doc/latest/ref/Tags/select.html?或者您是否想在任何字段中顯示下拉列表的選定值? –