jquery事件
来源:互联网 发布:微信小程序erp软件 编辑:程序博客网 时间:2024/06/05 17:17
data:
获取:$(this).data('industry');
$('.skill').toggle( function(){ //选中 $(this).css("background-color","lightblue"); $(this).css('color','white'); $(this).attr("data-state",'1'); }, function(){ $(this).css("background-color","white"); $(this).css('color','black'); $(this).attr("data-state",'0'); });
失败:不能单一去p1
<html><head><script type="text/javascript" src="/jquery/jquery.js"></script><script type="text/javascript">$(document).ready(function(){ $("p").live("click",function(){ $(this).slideToggle(); }); $("button").click(function(){ $("#p1").die(); });});</script></head><body><p id="p1">这是一个段落。</p><p class="c1">这是另一个段落。</p><p>请点击任意 p 元素,段落会消失。包括本段落。</p><button>移除通过 live() 方法向 p 元素添加的事件处理程序</button></body></html>
成功:
$(document).ready(function(){ $("#p1").live("click",function(){ $(this).slideToggle(); }); $("button").click(function(){ $("#p1").die(); });});
引:http://zhidao.baidu.com/link?url=b-ZafcLcFkVvK0vFN0MbdEqHcbQ7N6ijMlgFAYDm2AsMB3l4vmd31KUaqkvSGEi0DS7an-StTjOolbzlWxx2Oa
jQuery 1.9 已经将 live 和 die 移除,取而代之的是 on 和 off
1
2
3
$(
"#crawl_web ul li span"
).off(
'click'
);
$(
"#crawl_web ul li input"
).off(
'focus'
).off(
'blur'
);
$(
"#crawl_web ul li span"
).on(
'click'
,
function
(){
补充一下1楼的答案,live是给所有匹配的元素附加一个事件处理函数,即使这个元素是以后再添加进来的,但on、off方法是不能用来匹配以后添加进来的元素的。
比如点击按钮用ajax在某个div(id="xxx")上加载了一些元素(class="yyy"),那么操作这些元素(class="yyy")就不能直接用:
1
2
3
4
$(
".yyy"
).on(
"focus"
,
function
(){
// 操作
.....
});
应该改成:
1
2
3
4
$(
"#xxx"
).on(
"focus"
,
".yyy"
,
function
() {
// 操作
.....
});
0 0
- jQuery事件
- jquery事件
- JQuery事件
- JQuery事件
- jQuery事件
- jquery事件
- jQuery事件
- JQuery事件
- jquery 事件
- jquery事件
- jquery事件
- jQuery事件
- jQuery事件
- jQuery 事件
- jquery 事件
- jquery 事件
- JQuery事件
- jQuery 事件
- 视图总结
- ZOJ 3886 Nico Number(筛素数+Love(线)Live(段)树)
- Android Application对象必须掌握的七点
- uva10976_整数拆分(优化至3ms)
- 向服务器上传图片和一些数据信息
- jquery事件
- 解析数据与网络请求
- 存储过程和函数总结
- C语言32个关键字
- HDU 2680 Choose the best route 【最短路 反向建图 dijkstra & SPFA 】
- ArcServer 10安装完成后,访问ArcGIS Server Manager时出现HTTP 错误 500.19 - internet server error
- android实现Socket通信一
- 触发器总结
- CART算法原理及实现