체크 표시가있는 여러 확인란 (예 : html 코드)을 사용하면 두 필드에 동일한 데이터가 표시됩니다. 그래서 간단한 예제는 "additional monitor"와 "visio"를 체크하고 "* Required"를 보여 주도록하는 것입니다.많은 확인란이 표시/숨기기를 전환합니다.
html로 코드 :
<table>
<tr>
<td class="newemp_dataGLCCother">
<label for="gl_account">GL Acccount:</label>
<input name="gl_account" id="gl_account" type="text" maxlength="15" />
<label id="requiredgla" style="display:none"><font size="2" color="red">* Required</font>
</label>
</td>
</tr>
<tr>
<td class="newemp_dataGLCCother">
<label for="cost_center">Cost Center:</label>
<input id="" name="cost_center" id="cost_center" type="text" maxlength="15" />
<label id="requiredcc" style="display:none"><font color="red">*<font size="2"> Required</font></font>
</label>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="non_standard_software" value="Additional Monitor" id="additional_monitor" onclick="showReq('requiredgla'); showReq('requiredcc')" />Additional Monitor</td>
</tr>
<tr>
<td>
<input type="checkbox" name="non_standard_software" value="AutoCAD" id="autocad" onclick="showReq('requiredgla'); showReq('requiredcc')" />AutoCAD</td>
</tr>
<tr>
<td>
<input type="checkbox" name="non_standard_software" value="MapPoint" id="mappoint" onclick="showReq('requiredgla'); showReq('requiredcc')" />MapPoint</td>
</tr>
<tr>
<td>
<input type="checkbox" name="non_standard_software" value="Visio" id="visio" onclick="showReq('requiredgla'); showReq('requiredcc')" />Visio</td>
</tr>
<tr>
<td>
<input type="checkbox" name="non_standard_software" value="Project" id="project" onclick="showReq('requiredgla'); showReq('requiredcc')" />Project</td>
</tr>
<tr>
<td class="newemp_dataGLCCother">
<input type="checkbox" name="non_standard_software" value="other" id="other" onclick="showReq('otherbox'); showReq('requiredgla'); showReq('requiredcc')" />Other:
<input name="other" id="otherbox" type="text" style="display:none;" />
</td>
</tr>
자바 스크립트 :
이function showReq(id) {
var e = document.getElementById(id);
if (e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
그래서 당신은 "* 필수"항목의 홀수 번호를 확인 그대로이 코드로 표시되어 있지만 경우 표시되지 않은 짝수 개의 항목을 선택합니다.
그래서 변수를 "true"로 설정하고 js 함수에 여러 항목을 선택하면 토글을 제거 할 것이라고 생각했습니다.
예 :
function showReq(id) {
var dbl = true;
var e = document.getElementById(id);
if (e.style.display == 'block' && dbl === true)
e.style.display = 'none';
dbl = false;
else
dbl = true;
e.style.display = 'block';
}
나는이 작동하지 않는다는 것을 알고 있지만 나는이 비슷한 찾고 있어요. JavaScript를 완전히 사용할 수 없다면 jQuery를 사용하지 마십시오.
그래서 항상 표시하고 싶습니까? 'none'을 표시하기 위해 다시 설정하지 마십시오. 어떤 의미에서는 – PherricOxide
입니다. 따라서 1/2/3/4/5/6을 확인하면 표시된 그대로 유지되지만 모두 선택 해제하면 숨겨져 야합니다. – Benny