it's about actions that happen inside the browser.
HTML:
<button id="click-me">Click here</button>
<button id="hover-me">Move the cursor over here</button>
<button id="leave-me">Move the cursor out of here</button>
Javascript:
document.getElementById("click-me").onclick = function() {
alert('You clicked the button');
};
document.getElementById("hover-me").onmouseover = function() {
alert('You moved the cursor over the button');
};
document.getElementById("leave-me").onmouseout = function() {
alert('You moved the cursor out of the button');
};
document.onkeydown = function() {
alert('You pressed a key');
};
he keyCode property returns the Unicode of the pressed key.
針對指定按鍵做偵測
document.onkeydown = function (event) {
if (event.keyCode == "65") {
alert("Do something if letter 'a' is pressed.");
}
};
using HTML attributes:
<button onclick="show_alert()">Click here</button>
function show_alert() {
alert('You clicked the button');
}