Grails Radio按钮安排

时间:2016-10-13 07:14:55

标签: javascript jquery grails gsp

嗨我正在制作四个相互依赖的单选按钮。

按钮是First,second,A,B

First    Second
A         B

按钮就像我们选择第一,然后只选择第一,按钮 A B 变得禁用。如果我们选择第二,则 A B 都会启用,我们可以从中选择一个按钮。

<g:radioGroup name="RadioGrails"
              labels="['First','Second']"
              values="[1,2]">
<label>
        <span class="radioSpan">${it.radio}</span>
        ${it.label}
</label>
</g:radioGroup>

A和B的单选按钮

<g:radioGroup name="ABRadioButtons"
                  labels="['A','B']"
                  values="[1,2]">
    <label>
            <span class="radioSpan">${it.radio}</span>
            ${it.label}
    </label>
    </g:radioGroup>

1 个答案:

答案 0 :(得分:0)

我会用:

(当然,你必须设置第二个radioGroup的初始状态......)

<g:radioGroup class="radiograils" name="RadioGrails" labels="['First','Second']" values="[1,2]">
    <label>
        <span class="radioSpan">
            ${it.radio}
        </span> ${it.label}
    </label>
</g:radioGroup>

<g:radioGroup class="abradiobuttons" name="ABRadioButtons" labels="['A','B']" values="[1,2]">
    <label>
        <span class="radioSpan">
            ${it.radio}
        </span> ${it.label}
    </label>
</g:radioGroup>

<script src="${request.contextPath}/js/jquery-2.0.2.min.js"></script>
<script type="text/javascript">
    $('.radiograils').change(function() {
        if ($(this).val() == 2) {
            $('.abradiobuttons').prop('disabled', false);
        } else {
            $('.abradiobuttons').prop('checked', false);
            $('.abradiobuttons').prop('disabled', true);
        }
    });
</script>