this.value를 인수로 전달할 때 예기치 않은 토큰} 오류가 계속 발생합니다. 내 몸에서Javascript : Unexpected token}
내가 가진 :
<input type="text" size="3" id="rbgTextbox" onkeypress="if (ValidateRGBTextboxInput(event)) ChangeBackgroundColor("+this.value+"); else return false;">
기능 :
<script type="text/javascript">
function ValidateRGBTextboxInput(e) {
return ById('rbgTextbox').value.length < 6 &&
(e.which >= 48 &&
e.which <= 57 ||
e.which >= 65 &&
e.which <= 70 ||
e.which >= 97 &&
e.which <= 102);
}
function ChangeBackgroundColor(color) {
alert(color);
ById('gameArea').style.backgroundColor = '#'+color;
ById('nextPiece').style.backgroundColor = '#'+color;
}
</script>
내가 ChangeBackgroundColor를 변경하는 경우 ("+ this.value +"); ChangeBackgroundColor ('000000')에 대한; 더 이상의 오류는 없지만 물론 텍스트 입력 값을 인수로 전달해야합니다.
IE (및 IE 전용 코드 뼈를 던지는 Chrome과 같은 브라우저)를 제외하고는 'event'를 사용하면 작동하지 않습니다. 또한,'CheckKeyPress'를 호출하는 방법,'this'는 요소 참조가 아닙니다 (전역 객체가 될 것입니다). –