jquery实现相同事件名称,不同命名空间的调用方法
<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 js string">"width:100px;height:50px;background:#888;color:white;"
>test.</div>
<button >根据命名空间,触发事件</button>
</body>
</html>
- 上一篇 »JavaScript命名空间的理解与实现
- 下一篇 »php命名空间与可变函数