2009-09-02 1 views
1
<script type="text/javascript"> 
    function myfunction() { 
     if (document.getElementById('myform').value == "yes") { 
      document.getElementById('yesinput').style.display = ''; 
     } else { 
      document.getElementById('yesinput').style.display = 'none'; 
     } 
    } 
</script> 

<select name="myform" id="myform" onchange="myfunction()"> 
<option selected="selected">please select</option> 
    <option value="yes">Yes</option> 
    <option value="no">No</option> 
</select> 

<div id="yesinput" style="display:none"> 
<input name="input" type="text" /> 
</div> 

<div id="noinput" style="display:none"> 
<input name="input" type="text" /> 
</div> 

도움말 나중에. No을 선택하면 id = "noinput"아래에 다른 입력 필드가 생깁니다.자바 스크립트 - getElementById 및 도와주세요

을 선택하면 작동합니다. 알려주세요

+0

나는 무엇을 당신의 묻는 모른다. – Zoidberg

+0

LOL .. 죄송합니다. 더 자세히 설명하겠습니다. (언어 대부분) 어쩌면 누군가가 코드를 실행해야합니다 – wow

답변

4
function myfunction() { 
    if (document.getElementById('myform').selectedIndex == 0) { 
     document.getElementById('noinput').style.display = 'none'; 
     document.getElementById('yesinput').style.display = 'inline'; 
    } else { 
     document.getElementById('noinput').style.display = 'inline'; 
     document.getElementById('yesinput').style.display = 'none'; 
    } 
} 
+0

감사 카일 로젠도;) – wow

+1

물론, 다행히 도왔;) –

0

새 Element를 생성하고 Javascript를 통해 DOM에 추가 할 수 있습니다. 예 :

var newInput = document.createElement("input"); 
newInput.setAttribute("id", "newElement"); 
newInput.setAttribute("type", "text"); 
document.body.appendChild(newInput);