jQuery高级教程:根据命名空间,触发事件
jQuery高级教程:根据命名空间,触发事件的一个DEMO演示代码,请注意click后面的感叹号不能扔掉,否则错误。
答案:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>根据命名空间,触发事件</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="/ajaxjs/jquery1.3.2.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后面的感叹号
});
})
</script>
</head>
<body>
<div style="width:100px;height:50px;background:#888;color:white;">test.</div>
<button >根据命名空间,触发事件</button>
</body>
</html>
上一个:jQuery过滤HTML标签高亮显示关键字
下一个:jQuery与getJson结合的应用实例