欢迎您访问我爱IT技术网,今天小编为你分享的javascript教程:【JS delegate与live浅析】,下面是详细的讲解!
JS delegate与live浅析
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script src="http://www.jb51.net/article/jquery.js" type="text/javascript"></script>
<script id="listTemplate" type="text/html">
<tr>
<td>[UserID]</td>
<td>[UserImg]</td>
<td>[UserName]</td>
</tr>
</script>
<script type="text/javascript">
var reg=new RegExp("\\[([^\\[\\]]*?)\\]", 'igm'); //i g m是指分别用于指定区分大小写的匹配、全局匹配和多行匹配。
$(function () {
//live
$("#list td").live("click", function () {
alert($(this).html());
});
$("#addFun").click(function () {
var html=document.getElementById("listTemplate").innerHTML;
var source=html.replace(reg, function (node, key) { return { 'UserImg': '1', 'UserName': 'zhang', 'UserID': '1' }[key]; });
$("#list").append(source);
});
});
</script>
</head>
<body>
<div id="comment_ul_2">
</div>
<input type="button" id="addFun" value="click me" />
<table id="list" border="1">
<tbody>
</tbody>
</table>
</body>
</html>
关于JS delegate与live浅析的用户互动如下:
相关问题:jQuery事件绑定方法bind,live,delegate和on的区别
答:bind和on是一样的,bind是老方法,on是新方法,1.7以上才添加on方法,可作为bind替代,建议使用on方法。 live在1.7以下已经剔除,不建议使用live方法。delegate可最为live替代方法, delegate可以绑定一个或者多个事件,on只能 绑定一个事件 >>详细
相关问题:jQuery事件绑定方法bind,live,delegate和on的区别
答:bind是用来绑定一个或多个事件的,live其实bind的一个加强版,用来绑定通过JavaScript或者jQuery添加的DOM元素事件,其语法结构是一样 $("p").bind("mouseenter mouseleave",function(){alert("ok");})$("p").live("mouseenter mouseleave",func... >>详细
相关问题:delegate 方法 和重写有什么区别
答:区别在于:delegate()和.undelegate()方法实现的东西和.live()和.die()实现的东西是一样的,他们只是用不同的语法实现而已。对于方法.live(),它容许你给所有当前以及将来会匹配的元素绑定一个事件处理函数(比如click事件),也能绑定自定义事件... >>详细
- 【firefox】firefox浏览器不支持innerText的解决
- 【Extjs】Extjs学习过程中新手容易碰到的低级错误
- 【clearInterval】js clearInterval()方法的定义
- 【ComboBox】ComboBox 和 DateField 在IE下消失的
- 【dom】javascript dom追加内容实现示例-追加内容
- 【checkbox】让checkbox不选中即将选中的checkbox
- 【Array】js中更短的 Array 类型转换-类型转换
- 【append】append和appendTo的区别以及appendChil
- 【ExtJs】ExtJs 表单提交登陆实现代码-表单提交-
- 【ajax清除浏览器缓存】Ajax清除浏览器js、css、
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
