Home > Web Front-end > JS Tutorial > body text

Javascript implements the same event name and calling methods in different namespaces_javascript skills

WBOY
Release: 2016-05-16 15:52:21
Original
1079 people have browsed it

The example in this article describes the calling method of javascript to implement the same event name but different namespaces. Share it with everyone for your reference. The specific implementation method is 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事件</p>");
 });
 $("div").bind("click.plugin", function(){
   $("body").append("<p>click.plugin事件</p>");
 });
 $("button").click(function() {
   $("div").trigger("click!"); // 注意click后面的感叹号
   // click! 后面有叹号,是调用没有任何命名空间的click事件
   // click 后面没有叹号,是调用所有click事件(不管是那个命名空间的)
   // click.plugin 是调用某个特定命名空间的click事件(本例中是plugin)
 });
 })
 </script>
</head>
<body>
<div style="width:100px;height:50px;background:#888;color:white;">test.</div>
<button >根据命名空间,触发事件</button>
</body>
</html>

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!