在所选选项更改时显示和隐藏文本区域

时间:2016-09-08 14:33:28

标签: javascript jquery gsp

我需要一个文本区域,只有在选择了两个单选按钮时才会显示,就像我在第一种情况下选择值= 1而在第二种情况下选择值= 2。在其他情况下,文本区域应该消失。希望有人能提供帮助。感谢。

<div class="row top-margin" id="remote">
					<g:if test="${remote?.id == 1}">
<input type="radio" required name="remote" value="1" checked > <l:lookupLabe lookup="remote" id="1"/>
<input type="radio" required name="remote" value="2" > <l:lookupLabel lookup="remote" id="2"/>
					</g:if>
					<g:elseif test="${remote?.id == 2}">
<input type="radio" required name="remote" value="1" > <l:lookupLabel lookup="remote" id="1"/>
<input type="radio" required name="remote" value="2" checked > <l:lookupLabel lookup="remote" id="2"/>
					</g:elseif>
					<g:else>
<input type="radio" required name="remote" value="1" > <l:lookupLabel lookup="remote" id="1"/>
<input type="radio" required name="remote" value="2" > <l:lookupLabel lookup="remote" id="2"/>
					</g:else>
</div>
						

<div class="col-xs-12 col-sm-6" id="ref">
					<g:if test="${ref?.id == 1}">
<input type="radio" required name="ref" value="1" checked > <g:message code="default.yes.label"/>
<input type="radio" required name="ref" value="2" > <g:message code="default.no.label"/>
					</g:if>
					<g:elseif test="${ref?.id == 2}">
<input type="radio" required name="ref" value="1" > <g:message code="default.yes.label"/>
<input type="radio" required name="ref" value="2"  checked  > <g:message code="default.no.label"/>
					</g:elseif>
					<g:else>
<input type="radio" required name="ref" value="1" > <g:message code="default.yes.label"/>
<input type="radio" required name="ref" value="2" > <g:message code="default.no.label"/>
					</g:else>
</div>
					</div>				

<div id=divtext style='display:none'>  <textarea id="txt1"  name="title" > </textarea></div>

1 个答案:

答案 0 :(得分:0)

使用javaScrip,您可以执行以下操作:

var radio1 = document.getElementsByName('ref1'); var radio2 = document.getElementsByName('ref2');

if (radios1.checked && radio2.checked) {
    // do whatever you want with the checked radio
    // in this case will be display the textarea

    document.getElementById('txt1').style.display = 'block';
}

我希望我能提供帮助。