javascript implements invocation methods with the same event name and different namespaces
- 2020-06-22 23:48:46
- OfStack
This article is an example of how javascript implements the same event name, different namespaces call method. Share to everybody for everybody reference. Specific implementation methods are as follows:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("div").bind("click",function(){
$("body").append("<p>click The event </p>");
});
$("div").bind("click.plugin", function(){
$("body").append("<p>click.plugin The event </p>");
});
$("button").click(function() {
$("div").trigger("click!"); // Pay attention to click The exclamation point
// click! It is followed by an exclamation point and is called without any namespace click The event
// click There is no exclamation point, it is called all click The event ( Whatever the namespace is )
// click.plugin Is called to a particular namespace click Event (in this case, yes plugin )
});
})
</script>
</head>
<body>
<div style="width:100px;height:50px;background:#888;color:white;">test.</div>
<button > Triggers an event based on the namespace </button>
</body>
</html>
Hopefully, this article has been helpful in your javascript programming.