2013-04-17 7 views
1

저는 자바 초보자이며 텍스트 상자에 텍스트를 입력 할 때 활성화해야하는 동적 웹 단추를 만들려고합니다.동적 개체를 사용할 수 없음

아래 코드는 있지만 편집 상자에 텍스트를 입력하면 버튼이 활성화되지 않습니다.

누구나 친절하게 도와 드릴 수 있습니까?

<html> 
<form> 
<input onkeyup="EnableThis(this, document.getElementsByName('btnReplayType')[0])"name="txtReplayType" size="20" type="text"/> 
<input onclick="alert(document.getElementsByName('txtReplayType')[0].value)" disabled="65535" name="btnReplayType" size="20" type="button" value="Type and enable me" /> 
</form> 
</html> 

답변

2

여기에 수행 할 수있는 방법은 EXAMPLE입니다. 아래에서 인라인 이벤트 핸들러를 제거했다는 것을 알 수 있습니다. 이렇게하면 HTML을 더 읽기 쉽고 더 나은 방법으로 사용할 수 있습니다.

내가 어느 정도 도움이 발견했습니다 당신은 자바 스크립트를 처음 사용하는 자원을 찾는 경우 HTML

<form> 
    <input name="txtReplayType" size="20" type="text"/> 
    <input name="btnReplayType" size="20" type="button" value="Type and enable me" disabled /> 
</form> 

자바 스크립트

var text = document.getElementsByName('txtReplayType')[0], 
    button = document.getElementsByName('btnReplayType')[0]; 

text.onkeyup = function(){ 
    if(this.value !== ""){ 
     button.disabled = false; 
    } 
    else{ 
     button.disabled = true; 
    } 
}; 

button.onclick = function(){ 
    alert(text.value); 
}; 

, 내가 함께 a small page of links를 넣었습니다 (자습서, 사양 문서 등 포함).

관련 문제