다음 코드에서 실행하면 경고를 발생시키는 click 이벤트를 기다립니다. 내가JavaScript에서 두 가지 다른 함수 호출 방법
에서 다음 자바 스크립트 코드을 변경하지만 경우
에clickMeButton.onclick = runTheExample;
clickMeButton.onclick runTheExample =();
클릭 이벤트없이 페이지를 다운로드 할 때 항상 경고가 발생합니다. 차이점을 알고 싶습니다. Chrome을 사용 중입니다. 냈다 코드는 다음과 같습니다
<!DOCTYPE html>
<html>
<head>
<title>DOM Example</title>
<script type="text/javascript" src="script13.js"> </script>
</head>
<body>
<h1 id="title">DOM Example </h1>
<p id="first">This is the first paragraph</p>
<p id="second"><strong>This is the second paragraph</strong></p>
<p id="third">This is the third paragraph</p>
<input type ="text" id="myTextBox" />
<input type ="submit" id="clickMe" value="Click Me!"/>
<a href="http://www.google.com" id="MyGoogle"> Google! </a>
</body>
</html>
//script13.js
window.onload= function(){
var clickMeButton=document.getElementById('clickMe');
clickMeButton.onclick=runTheExample;
}
function runTheExample(){
alert('running the example');
}
당신이 VAR X = FUNC를() 당신이 기능을 실행하고 기능 실행의 VAR X = 수익을하고 있습니다 호출 할 때 나는 생각한다. 그리고 var = func을 호출하면 var x가 이제는 함수라는 것을 알 수 있습니다. –
두 번째 표기법에서'clickMeButton.onclick'은'runTheExample()'의 ** 값 반환 **에 할당되는 반면, ** 참조 **는 함수 ('runTheExample')에 대한 것입니다 – hindmost
고마워, 포인트. – casillas