事件click,bind,click
<!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的更多相关文章
- jquery阻止冒泡事件:$('span').bind("click",function(event){event.stopPropagation();})(有用源)
冒泡事件就是点击子节点,会向上触发父节点,祖先节点的点击事件. <body> <div id="content"> 外层div元素 <span> ...
- jQuery绑定事件方法及区别(bind,click,on,live,one)
第一种方式: ? 1 2 3 4 5 $(document).ready(function(){ $("#clickme").click(function(){ alert(& ...
- jQuery的.click,.bind,.unbind,.on,.off,.delegate,.undelegate
.click与.bind .click和.bind都是给每个元素绑定事件,对于只绑定一个click事件,.bind事件的简写就是.click那种方式. 这两种方式都会出现两个问题: 第一个问题,如果要 ...
- jquery 事件委托绑定click的使用方法
直接绑定ul的click事件 代码如下 复制代码 $("ul").click(function(e) 例子 代码如下 复制代码 $(function(){ //$(" ...
- jQuery方法区别:click() bind() live() delegate()区别
今天看到一篇jquery 事件的文章,自己写了个小例子,虽然2种方式都可以实现,但是不太明白,找了点资料 $("#box1").delegate("p",&qu ...
- jQuery方法区别(四)click() bind() live() delegate()区别
click(),bind(),live()都是执行事件时使用的方法,他们之前是有一些区别的,我们在使用这些方法时应该根据需要进行选择. 1.click()方法是我们经常使用的单击事件方法: $ ...
- jquery .live() .delegate() .bind() .click()区别
什么是.live()? 除了让你对Dom元素现在和将来绑定事件之外,.live() 方法和.bind()方法很像.你可以用.live()方法对没有存在的Dom节点绑定事件.考虑下面的情况. 当用户要离 ...
- click() bind() live() delegate()区别
click(),bind(),live()都是执行事件时使用的方法 1.click()单击事件方法: $("a").click(function() { alert("h ...
- one(type,[data],fn) 为每一个匹配元素的特定事件(像click)绑定一个一次性的事件处理函数。
one(type,[data],fn) 概述 为每一个匹配元素的特定事件(像click)绑定一个一次性的事件处理函数. 在每个对象上,这个事件处理函数只会被执行一次.其他规则与bind()函数相同.这 ...
- 当一个HTML元素需要添加mouseon、mouseout与click事件,或者mouserenter、mouseleave和click事件时,click事件无法触发
当一个HTML元素需要添加mouseon.mouseout与click事件,或者mouserenter.mouseleave和click事件时,click事件无法触发 针对上述问题,我遇到的有两种情况 ...
随机推荐
- Oracle sql中的正则表达式
SELECT first_name, last_nameFROM employeesWHERE REGEXP_LIKE (first_name, '^Ste(v|ph)en$'); FIRST_NAM ...
- C#面向对象(OOP)入门—第二天—多态和继承(继承)
介绍: 第一天的内容主要是不同情形下的方法重载.这一部分则主要讲面向对象中继承的概念.首先用一个要点图形来定义继承. 继承 一个简单的例子: ClassA: class ClassA:ClassB { ...
- Leetcode 之Length of Last Word(37)
扫描每个WORD的长度并记录即可. int lengthOfLast(const char *s) { //扫描统计每个word的长度 ; while (*s) { if (*s++ != ' ')/ ...
- margin和spacing的区别
margin指的是与边框间的距离. spacing指的是组件间的距离
- CentOS7.5安装notepadqq
这个notepadqq就是linux版本的notepad了 1.添加yum源 sudo wget -O /etc/yum.repos.d/sea-devel.repo http://sea.fedor ...
- hdu 1874 畅通工程(spfa 邻接矩阵 邻接表)
题目链接 畅通工程,可以用dijkstra算法实现. 听说spfa很好用,来水一发 邻接矩阵实现: #include <stdio.h> #include <algorithm> ...
- php过滤表单输入的emoji表情
1.过滤emoji表情的原因 在我们的项目开发中,emoji表情是个麻烦的东西,即使我们可以能存储,也不一定能完美显示,因为它的更新速度很快:在iOS以外的平台上,例如PC或者android.如果你需 ...
- 141. Linked List Cycle【Easy】【判断链表是否存在环】
Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked lis ...
- 洛谷P1955 [NOI2015] 程序自动分析 [并查集,离散化]
题目传送门 题目描述 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3...代表程序中出现的变量,给定n个形如xi=xj或x ...
- Flask实战第53天:cms编辑轮播图功能完成
后端逻辑 表单验证, 这里编辑就是和添加的内容一样,所以可以直接继承添加轮播图的表单验证,然后多加一个轮播图的id即可 编辑cmd.forms.py class UpdateBannerForm(Ad ...