您好我有以下复选框
<div class="checkbox">
<label for="sendEmail">
<g:checkBox name="sendEmail" checked="${sendEmail == 'on'}"
onchange="swapFieldsets(this, '#sa-email', '#sa-password')" />
<g:message code="onBoard.noAccessEmail" default="Send Access Email" />
</label>
</div>
如果是打开/关闭它会这样做:
<fieldset id="sa-email" ${raw(sendEmail == "on" ? "" : "class='hidden' disabled")}>
<g:render template="businessEmailFields" bean="${pEmail}" />
</fieldset>
<fieldset id="sa-password" ${raw(sendEmail != "on" ? "" : "class='hidden' disabled")}>
<g:render template="homeEmailFields" bean="${pEmail}" />
</fieldset>
现在我想通过替换它来删除复选框 并保持相同的逻辑
<g:select name="book.category" from="${['Choice1', 'Choice2']}"
/>
如果我们从菜单Choice1中选择渲染
<g:render template="homeEmailFields" bean="${pEmail}"/>
如果我们选择Choice2来呈现另一页
总结一下,我想:我只想删除复选框并将其替换为下拉菜单,其中包含选项&#39; Choice1&#39;并且&#39; Choice2&#39;。你可以看到它与hitbox一样,我们应该渲染一个页面,现在我不想知道它是否打开我想检查我们是否选择了下拉菜单&#39; Choice1&#39;
答案 0 :(得分:0)
正如我在评论中提到的,您通常会有select box
<g:select class="form-control small" name="adminButtons" from="${adminButtons}"
noSelection="${['':"${g.message(code:'queuekit.chooseAdminAction.label')}"]}"
valueMessagePrefix="queuekit.adminButton"/>
然后调用through jquery,然后你会change that to
$('#adminButtons').on('change', function() {
var value = $('#adminButtons').val();
if (value!='') {
var params=$.param({changeType:value});
var url='${createLink(controller:'queueKit',action:'changeConfig')}?'+params
$.ajax({
type: 'POST',
url: url,
//data: $('#search').serialize(),
success: function(data){
//Where #results id the DIV id that the template is loaded
//into which would be your template you are loading
$('#results').html(data);
}
});
}
});
但是那不是试图通过gsp查找实际值以改变gsp - 然后你的gsp将通过ajax调用加载到你的控制器加载一个模板作为你的模板......
与您的工作方式略有不同,但通常是如何完成javascript交互