이것은 내 코드입니다. 여기서 호스트 이름은 배열입니다. 모든 배열 요소에 대해 내 루프가 반복됩니다. 사용자가 yes를 선택하면 hideconf div 요소가 표시됩니다. 그렇지 않으면 요소를 숨겨야합니다. 그러나 첫 번째 반복에서만 작동합니다. 두 번째 반복에서 첫 번째 div 태그의 요소가 표시되고 숨겨집니다. 문제는 이드에 있습니다. 그래서 어떻게 내 목표를 달성 할 수 있습니까?
<% hostname.forEach(function(data){ %>
<input class="form-control" id="fw" name="fwchange" type="radio" value="true" onclick="showconf()" /></label>
<input class="form-control" id="fw" name="fwchange" type="radio" value="true" onclick="noshowconf()" /></label>
<div class="hideconf" style="display:none">
<input type="text" class="form-control" id="fwchangedetail" name="fwchangedetail" placeholder="Configuration Change Details"/>
<input type="text" class="form-control" id="fwchangedetail1" name="fwchangedetail1" placeholder="Configuration Change Details"/>
<input type="text" class="form-control" id="fwchangedetail2" name="fwchangedetail2" placeholder="Configuration Change Details"/>
<input type="text" class="form-control" id="fwchangedetail3" name="fwchangedetail3" placeholder="Configuration Change Details"/></div>
<%}) %>
<script>
function showconf(){
document.getElementsByClassName('hideconf').style.display="block";}
function noshowconf(){
document.getElementsByClassName('hideconf').style.display="none";}
</script>
이 행운을 빕니다 :)
<% hostname.forEach(function(data, index){ %>
<input class="form-control" id="fw" name="fwchange" type="radio" value="true" onclick=`showconf(${index})` /></label>
<input class="form-control" id="fw" name="fwchange" type="radio" value="true" onclick=`noshowconf(${index})` /></label>
<div class="hideconf" style="display:none">
<input type="text" class="form-control" id="fwchangedetail" name="fwchangedetail" placeholder="Configuration Change Details"/>
<input type="text" class="form-control" id="fwchangedetail1" name="fwchangedetail1" placeholder="Configuration Change Details"/>
<input type="text" class="form-control" id="fwchangedetail2" name="fwchangedetail2" placeholder="Configuration Change Details"/>
<input type="text" class="form-control" id="fwchangedetail3" name="fwchangedetail3" placeholder="Configuration Change Details"/></div>
<%}) %>
<script>
function showconf(index){
document.getElementsByClassName('hideconf')[index].style.display="block";}
function noshowconf(index){
document.getElementsByClassName('hideconf')[index].style.display="none";}
</script>
======= 업데이트 =========
Cuz document.getElementsByClassName
는 NodeList 배열을 반환합니다. 귀하의 기능에서 u는 첫 번째 요소의 스타일을 변경했습니다.
// the index is the NodeList's index
document.getElementsByClassName('hideconf')[index].style.display
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다