HTML, click () and onclick () the difference between the nature of the case and explain

HTML, click () and onclick () is the essential difference between cases and interpretation; divided into four points;

The first point: the English translation:
the On the meaning is: open, connected, triggers mouse events ;
show onclick () represents an event; while in HTML, click () as a method;

The second point: Chinese explanation:
What is the event? What is the method?
Event: mouse event triggering condition, such as a mouse to draw and paddled, click, double click and the like
methods: a process, i.e., from the code section of the package and package defined, easy reuse, to avoid duplication;
simply referred to as : event: trigger event, method: processing;

The third point :: click () and onclick () relationship
onclick () event is binding: the role execute the function code;
the Click () method itself: the role of a trigger event is onclick ()
code sample:

<html>
	<meta charset="utf-8" />
<head>
    <script type="text/javascript" src="js/jquery-1.12.4.js"></script>
	
</head>
<body>
<script type="text/javascript"> 
$(function(){
	$("#b2").click(function(){
	$("#b1").click();
});});
function change(){
	alert("调用了方法change");
}

</script> 
<button id = "b1" onclick="change()">按钮1</button>
<button id = "b2">按钮2</button>
 
</body>
</html>

Explained:
onclick () is a binding events, tells the browser what to do when clicking on a mouse
click () method itself is the role are: trigger onclick () event
code that nature:
just click the implementation of the elements () method is triggered onclick () event.
As shown in the code of Appeal, when clicking button 2 button, the trigger button 1 click the () method, and click () method triggers the onclick () event;
Conclusion one: the implementation of the click elements () method triggers a call click elemental onclick event
results:
click the button 1: Popup: to call a method change
click the button 2: Popup: to call a method change

The fourth extension :: click () of the
can add in cliick () function in the role of an additional method of events;
click process after the execution of the function code in execution onclick event, then click method additionally play event effect.
Code Example:

<html>
	<meta charset="utf-8" />
<head>
    <script type="text/javascript" src="js/jquery-1.12.4.js"></script>
	
</head>
<body>
<script type="text/javascript"> 
$(function(){
	$("#b1").click(function(){
    alert("调用了click()方法的追加事件");
	});});
function change(){
	alert("调用了方法change");
}

</script> 
<button id = "b1" onclick="change()">按钮1</button>

 
</body>
</html>

Explanation:
performing click () method after, Change in the execution tag () event, and then performs internal click (Method package internal functions alert () method);
Results:
first pop call method Change , then the pop- called click () method of additional events ;

Reference and reference sites:
https://www.feiniaomy.com/post/340.html
https://www.jb51.net/article/55650.htm

I do not know if you can add and practicing oh;
individuals also have free university graduates defense sites and total set;
and providing free software and instructional videos;
QQ + 2545062785

Published 15 original articles · won praise 13 · views 3351

Guess you like

Origin blog.csdn.net/weixin_45673401/article/details/104129624