JavaScript event handling learning method

1. Understanding JavaScript Events

     The HTML document binds the common events of the element (such as onlick, onmouseover, etc.) as attributes on the HTML element. When a specific event of the element occurs,

The event handler corresponding to this particular event is executed and the result is returned to the browser. Event bundling causes specific code to be placed in the event handler of the object in which it resides.

2. Small problems at runtime


js is a script, so this phenomenon occurs, right-click on a single machine and select Allow to appear

Click Yes and that's it. You can see what you want.

2. Bind the click event for the button

1. The effect is as shown in the figure





2. The code is as follows

<html>

<head>
<title>事件处理器</title>
<script type="text/javascript" >
window.onload=function(){
var btn=document.getElementById('btnSubmit');
btn.onclick=function(){
alert('你点击了'+this.value+'按钮');
}
}
</script>
</head>


<body>
<input type="button" id="btnSubmit" value="提交" />
                                   
</body>

</html>

3. Explanation


This part uses anonymous functions: function defines an anonymous function bound to the onload event.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325166976&siteId=291194637