jQuery 1.4.2中的.bind(),.live()&.delegate()方法解析
发布日期:2021-05-14 04:36:50 浏览次数:14 分类:博客文章

本文共 2916 字,大约阅读时间需要 9 分钟。

.bind������������

.bind������������������������������������������������������������������������������������������������������������������������������������.bind()���������������������������������������������������������������������������������������������������������������������.bind()������������������������������������dom���������������������������������������������������

���������������

 

jQuery: $(
'
.alertMe
'
,
'
#bindExample
'
).bind(
'
click
'
,
function
() { alert(
'
Clicked!
'
); }); $(
'
#bindExample
'
).append(
'

Alert does not fire on click!

'
); HTML:
<
div id
=
"
bindExample
"
>
<
p class
=
"
alertMe
"
>
Alert fires on click
!<
/
p>
<
/
div>

 

���������������������������������������������������������������������������������

 

.live()������

���.bind()���������������.live()���������������������������������������������������������������������������,.live()������������������������������������������������������������������������������������������������������.live()������������������������������

���������������������dom������������������������������������jQuery������������������������������������������

$('#foo').children('.bar').live('click',function(){//do something });

������������������

$('#foo .bar').live('click', function() { /do something }); 

���������������������������������������������������������.find()���������������������������������

���������������

jQuery: $(
'
.alertMe
'
,
'
#liveExample
'
).live(
'
click
'
,
function
() { alert(
'
Clicked!
'
);});$(
'
#liveExample
'
).append(
'

Alert fires on click (even though this was added after .live() was called)!

'
);HTML:

Alert fires on click!

������������������������������������������

 
.delegate()������
.delegate()���������live������������������������������������������������������������live������������4��������������������������������������������������������������������������������������������������������������������� $('#foo').delegate('.bar', ...)������������������.bar���������������������������������������������#foo���������������������������������������������������������������������ajax������������������������������������������������������������������
.delegate()���������dom���������������������������������.live()������������
���������������
jQuery: $(
'
#delegateExample
'
).delegate(
'
.alertMe
'
,
'
click
'
,
function
() { alert(
'
Clicked!
'
);});$(
'
#delegateExample
'
).append(
'

Alert fires on click (even though this was added after .delegate() was called)!

'
);HTML:

Alert fires on click!

上一篇:javascript中的event.keycode大全
下一篇:GridView的另外一种分页方式,可提高加载速度

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2025年04月28日 11时21分50秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章