JavaScript event
JavaScript event is an event. Designers use event handlers in the code to monitor the user’s Events behavior. Usually Event is used with functions to perform certain actions. The built-in JavaScript core of the browser itself Determine what actions the user produces, for example, click action to use onclick event to monitor, to change a field in the form to use onchange event to monitor, when the mouse moves over a block, to use onmouseover to monitor... etc. When the user's action occurs, it can trigger a specific function to execute. The above is the basic concept of JavaScript event. In principle, the standard writing of every event in JavaScript grammar is English lowercase, unless it is used in HTML Don’t worry about capitalization, otherwise, it’s recommended not to write onchange as onChange, it is likely that the script will not be executed. In addition, JavaScript Event itself also has abbreviations, but not every browser can support abbreviations, it is recommended to use standard writing , Here are a few reference examples.
JavaScript event example 1: onclick
function ShowToday(){
var Today=new Date();
alert("Today's date is" + Today.getFullYear()+ "year" + (Today.getMonth()+1) + " Month" + Today.getDate() + "Day");
}
</script>
<input type="button" onclick="ShowToday()" value="Today's day of the week">
JavaScript event example two, onblur
function TestOnblur(){
alert('test onblur');
}
</script>
<input type="text" onblur="TestOnblur()">
JavaScript event example three, onchange
function TestOnchange(){
alert('test onchange');
}
</script>
<select onchange="TestOnchange()">
<option>option A</option>
<option>option B </option>
</select>
JavaScript event example 4: onmouseover
function ChangeBgColor(){
document.getElementById("TBox").style="width:200px;height:60px;background-color:#FFC9C9;";
}
</script>
<div onmouseover ="ChangeBgColor()" id="TBox" style="width:200px;height:60px;background-color:#FFCC6E;">
Mouse over here will change the color
</div>
JavaScript event common event table
Event | Description |
onclick | When the user clicks on an element, for example, select an option or button ( button ). |
onchange | When the element changes, such as when selecting other items in the select option . |
onblur | When the cursor loses focus, that is, when clicking other areas, it is usually used to fill in a field of the form . |
ondblclick | Clicking a specific element twice in a row is usually used in situations that require specific confirmation. |
onfocus | When web page elements are locked, such as textarea , input text . |
onload | The function is triggered immediately after the page is loaded. |
onmousedown | Mouse event, when the mouse button is pressed. |
onmouseover | Mouse event, when the mouse cursor moves over an element or block. |
onmousemove | Mouse events, when the mouse cursor moves. |
onmouseout | Mouse event, when the mouse moves out of an element or block. |
onmouseup | Mouse event, when the mouse button is released. |
onunload | When netizens are about to leave the page. |
Post a Comment
0 Comments