JavaScript is event-driven; JavaScript is a scripting language that is object- and event-driven and has security capabilities. Event-driven is triggered by mouse or hotkey actions. The event processing process is that the event occurs first. , then start the event handler and react.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
Javascript is event-driven
Event-driven events in javascript are triggered by mouse or hotkey actions . The main events are as follows:
1. Mouse click event onclick
2. Content change event onchange
3. Select event onselect -- when the content of text or textarea is This event is triggered after highlighting
4. Obtain focus event onFocus--occurs when the object obtains focus
5. Lose-focus event onBlur--Corresponds to the focus-gaining event!
6. Document loading event onload --The event is triggered when the document is loaded. It is also usually called a loading event (loading run) and is generally used to set cookies
7. Unload document event onunload --corresponds to the load document event. Occurs when the web page exits, usually updating the cookie value
8. Right mouse button menu function event oncontextmenu -- you can use
event processing when you can shield the right mouse button:
1 .The event occurs
2. Start the event handler (triggered by the event handler)
3. The event handler reacts to the call of the
event (both are triggered by the event handler) caller), examples are as follows:
1. Call
<input name="save" type="button" value="保存" onclick="alert('Click the button');" />
2. Call
<input id="save" type="button" /> <script> var b=document.getElementById("save"); b.onclick=function(){ alert("Click the button"); } </script>
in Javascript. In the above code, be sure to put the Javascript script Under the element mark, because the Javascript language is an interpreted language, the execution order is line by line in order. Only in this way can variable b obtain the element mark object
In the browser, the event object is the window object An attribute event, whose function is to obtain the object that triggered the event when the event is triggered. In IE browser, the event object is actually contained in the srcElement attribute of even; in DOM browser (not IE browser), the event object It is really included in the target attribute of the event
function someHandle(){ var oEvent; if(window.event==true){ //判读是否存在事件对象 oEvent=window.event; } var oTarget; if(oEvent.srcElement==true){ oTarget=oEvent.srcElement; //IE浏览器 } else{ oTarget=oEvent.target; //DOM浏览器 } alert(oTarget.tarName); //弹出目标对象的标记名称 } window.onload=function(){ var oImg=document.getElementsByTagName("img")[0]; //获取一组name为img的标记的第一个 oImg.onclick=someHandle(); }
[Related recommendations: javascript video tutorial, web front-end】
The above is the detailed content of Is javascript event driven?. For more information, please follow other related articles on the PHP Chinese website!