자바 스크립트에서 첫 번째 코드를 작성하고 있습니다. 경고 에서 onClick 이벤트가 자바 스크립트에서 호출되지 않음
- 로드 이미지를
- 가 이름을 작성 후 사용자 이름
- 요청 이미지를 - :
나는이 작업을 수행 할 수
내 코드는 다음과 같이 변경됩니다.
<!DOCTYPE html> <html> <head> <title>iRock - First Project</title> <script type = "text/javascript"> function touchRock(){ var userName = prompt ("what is your name?","Enter your name here."); if(userName){ alert("It is good to meet you, " "+userName+ " "."); document.getElementById("firstImg").src="1.jpg"; } } </script> </head> <body onload = "alert('hello, I am your pet.');"> <div style = "margin-top:100px; text-align:centre"> <img id="firstImg" src="http://www.smiley-faces.org/wallpaper/smiley-face-wallpaper-widescreen-001.jpg" alt="iRock" style="cursor:pointer" onclick="touchRock()" /> </div> </body> </html>
아무도이 문제가 무엇인지 나에게 말해 줄 수 있습니까? 이미지를 만진 후에도 이벤트가 호출되지 않기 때문입니다.
먼저 브라우저에서 Javascript 콘솔을 사용하는 방법을 배워야합니다. 코드에 구문 오류가있는 경우이를 알려줍니다. – Barmar
http://jsfiddle.net/DfSHS/ - 경고문에 오류가 있습니다. 피들이 수정되었습니다. – dchhetri
@ user814628 질문에 대답하려면 의견이 아닌 대답으로 게시하십시오. – Barmar