<!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. 关于ASP .NET Core在跨平台的linux ubuntun,SUSE ,Mac OS的发布的相关平台操作

    https://www.microsoft.com/net/learn/get-started/linuxopensuse

  2. 使用 Visual Studio 部署 .NET Core 应用 ——.Net Core 部署到Ubuntu 16.04

    .Net Core 部署到Ubuntu 16.04 中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是服务 ...

  3. 【msgpack-python】安装

    1.安装pip:http://blog.iyestin.com/2014/03/15/python-pip-install/ http://www.linuxde.net/2014/05/15576. ...

  4. mysql大法

    mysql大法 MySQL 安装方式 1.rpm(yum) 2.源码包 3.通用二进制 企业中版本选择 5.6 5.7 选择 GA 6个月到1年之间的------------------------- ...

  5. HDU 3669 Cross the Wall(斜率DP+预处理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3669 题目大意:有n(n<=50000)个矩形,每个矩形都有高和宽,你可以在墙上最多挖k个洞使得 ...

  6. ORM数据库查询操作之基于双下划线的跨表查询

     创建表结构 from django.db import models class Book(models.Model): title=models.CharField(max_length=32) ...

  7. Balanced Binary Tree——经典题

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...

  8. ffmepg的基本使用

    基本使用命令 ffmpeg -i input.mp4 output.avi //视频格式转换 ffmepg -i input.mp4 -r fps image%3d.jpg //视频转成图片 //fp ...

  9. Linux下源码安装jdk

    1.到官网下载 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

  10. Linux下安装rz、sz命令(文件上传下载)

    yum install -y lrzsz 说明:rz命令本地上传文件到服务器:sz命令发送文件到本地.