JavaScript の初心者は、
addEventListener()
関数、の使用とは対照的に
variable.onclick
これが私がテストしているコードです
/*
* A simple function to swap the text of two elements
*/
function swapFunction(){
var siteTitle = document.getElementById("site_title");
var siteText = document.getElementById("site_text");
var temp = siteTitle.innerHTML;
siteTitle.innerHTML = siteText.innerHTML;
siteText.innerHTML = temp;
return false;
}
/*
* A function to handle the page load
*/
function fullyLoaded(){
var testEvent = document.getElementById("test_click");
/*
* Why does the line that has been commented out not work
* Yet the line beneath it does?
*/
//testEvent.addEventListener("click", swapFunction(), false);
testEvent.onclick = swapFunction;
}
window.onload = fullyLoaded;
HTML
<html>
<head>
<title>This is a test application</title>
</head>
<body>
<h1 id="site_title">Welcome To My Site</h1>
<p id="site_text">This is a test site that I am practicing on</p>
<a id="test_click" href="#">test click</a>
</body>
</html>
IE のイベント ハンドラと addEventListener() または attachEvent() の概念を説明してください。
前もって感謝します