<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<style type="text/css">
#box1,#box2,#box3{float:left;background:red; width: 50px;}
#box2,#box3{margin-left:10px;}
.a{ width: 50px; height: 50px; background: green;float: left;}
.addbox{ width:50px; height:50px; background:green; border-bottom:2px solid #000;}
</style>
<script type="text/javascript">
$(function(){
var a="<div class='a'>点击这里</div>";
$("#box1").append(a);
$("#box2").append(a);
$("#box3").append(a);
$("#box1 .a").click(function(){$("#box1").append(a);})
$("#box2 .a").bind("click",function(){$("#box2").append(a);})
$("#box3 .a").live("click",function(){$("#box3").append(a);})
})
</script>
</head>
<body>
<div id="box1">
click
</div> <div id="box2">
bind
</div> <div id="box3">
live
</div>
</body>
</html>

点击效果:

使用 live() 方法向新创建的元素添加事件处理器

相关文章:

jQuery的.bind()、.live()和.delegate()之间区别

事件click,bind,click的更多相关文章

  1. jquery阻止冒泡事件:$('span').bind("click",function(event){event.stopPropagation();})(有用源)

    冒泡事件就是点击子节点,会向上触发父节点,祖先节点的点击事件. <body> <div id="content"> 外层div元素 <span> ...

  2. jQuery绑定事件方法及区别(bind,click,on,live,one)

    第一种方式: ? 1 2 3 4 5 $(document).ready(function(){  $("#clickme").click(function(){  alert(& ...

  3. jQuery的.click,.bind,.unbind,.on,.off,.delegate,.undelegate

    .click与.bind .click和.bind都是给每个元素绑定事件,对于只绑定一个click事件,.bind事件的简写就是.click那种方式. 这两种方式都会出现两个问题: 第一个问题,如果要 ...

  4. jquery 事件委托绑定click的使用方法

    直接绑定ul的click事件  代码如下 复制代码 $("ul").click(function(e) 例子  代码如下 复制代码 $(function(){ //$(" ...

  5. jQuery方法区别:click() bind() live() delegate()区别

    今天看到一篇jquery 事件的文章,自己写了个小例子,虽然2种方式都可以实现,但是不太明白,找了点资料 $("#box1").delegate("p",&qu ...

  6. jQuery方法区别(四)click() bind() live() delegate()区别

        click(),bind(),live()都是执行事件时使用的方法,他们之前是有一些区别的,我们在使用这些方法时应该根据需要进行选择. 1.click()方法是我们经常使用的单击事件方法: $ ...

  7. jquery .live() .delegate() .bind() .click()区别

    什么是.live()? 除了让你对Dom元素现在和将来绑定事件之外,.live() 方法和.bind()方法很像.你可以用.live()方法对没有存在的Dom节点绑定事件.考虑下面的情况. 当用户要离 ...

  8. click() bind() live() delegate()区别

    click(),bind(),live()都是执行事件时使用的方法 1.click()单击事件方法: $("a").click(function() { alert("h ...

  9. one(type,[data],fn) 为每一个匹配元素的特定事件(像click)绑定一个一次性的事件处理函数。

    one(type,[data],fn) 概述 为每一个匹配元素的特定事件(像click)绑定一个一次性的事件处理函数. 在每个对象上,这个事件处理函数只会被执行一次.其他规则与bind()函数相同.这 ...

  10. 当一个HTML元素需要添加mouseon、mouseout与click事件,或者mouserenter、mouseleave和click事件时,click事件无法触发

    当一个HTML元素需要添加mouseon.mouseout与click事件,或者mouserenter.mouseleave和click事件时,click事件无法触发 针对上述问题,我遇到的有两种情况 ...

随机推荐

  1. android 图片透明

    在ImageButton中载入图片后,图片周围会存在一圈白边,会影响到美观,其实解决这个问题有两种方法 一种方法是将ImageButton的背景改为所需要的图片.如:android:backgroun ...

  2. Context-Aware Network Embedding for Relation Modeling

    Context-Aware Network Embedding for Relation Modeling 论文:http://www.aclweb.org/anthology/P17-1158 创新 ...

  3. java-增强for循环

    public static void main(String[] args) { ArrayList<String> list = new ArrayList<>(); lis ...

  4. sql server 2008 R2连接失败 错误:18456

    这种问题的解决方法: 第一步:以windows验证模式进入数据库管理器. 第二步:在对新资源管理器中右击实例名称选择属性,弹出服务器属性对话框,我们在左侧栏选择[安全性]选项卡,选中”SQL Serv ...

  5. python中使用pyqt做GUI小试牛刀

    import sys from PyQt4 import QtGui , QtCore class LIN(QtGui.QMainWindow): def _init_(self): QtGui.QM ...

  6. 【JBPM4】流程分支fork - join

    流程分支.聚合.流程每个分支节点都全部处理完成后,聚合到下一个节点. JPDL <?xml version="1.0" encoding="UTF-8"? ...

  7. NOI2014 魔法森林 day1t2 SPFA

    这道题做法还是很多的,至少有人用最优性剪枝当场A掉了.我只有50分的暴力分(写丑了),SB我不会LCT,先写一下SPFA的神思路做法(说白了还是我SB),LCT以后定补.ORZ想出来的人(hq大神). ...

  8. <<持续交付>>终点的精彩

    1,向敏捷转变的过程是一个很容易出乱子的过程, 尤其对项目的领导力来说.在实施敏捷的过程中,会突然释放出一些有用的信息,将原来隐蔽起来的真相推倒聚光灯下. 2,假如执行者忽略了技术实践(比如测试驱动开 ...

  9. 洛谷P1196 [NOI2002] 银河英雄传说

    #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #includ ...

  10. 洛谷——P2035 iCow

    P2035 iCow 题目描述 被无止境的农活压榨得筋疲力尽后,Farmer John打算用他在MP3播放器市场新买的iCow来听些音乐,放松一下.FJ的iCow里存了N(1 <= N < ...