作者TonyQ (沉默是金。)
看板Ajax
标题Re: [ js ] jquery live event的问题
时间Sun Apr 18 10:55:23 2010
※ 引述《rexkimta (冷杉林)》之铭言:
: --
:
※ 发信站: 批踢踢实业坊(ptt.cc)
: ◆ From: 140.114.217.84
: 推 tomin:你自己复制一下贴上来的code 还是只会alert 1次呀 04/18 01:17
: 推 tomin:http://sites.google.com/site/tominxd/card.html 04/18 01:28
: → tomin:我试是只有1次呀 04/18 01:28
: → rexkimta:耶,我发现问题在那了…我这段程式码写在ajaxcomplete里 04/18 01:34
: → rexkimta:把这段写在$.getjson的callback里就可以了…… 04/18 01:35
: → rexkimta:和我之前以为的问题点不一样= = 不过还是不知道为什麽会 04/18 01:36
: → rexkimta:这样。 04/18 01:36
: → rexkimta:另外,.card里的图档档名是透过ajax抓回来的。 04/18 01:37
: → rexkimta:而.card是ajax抓完後才产生的,所以要写在callback里。 04/18 01:38
简单来说绑定的动作执行至少两次才会发生这种情形 ,
另外你请重新思考一下 live 的定义 ,
live 就是不需要在意元素是否存在与否 .
(他绑定的不是特定对象, 而是特定条件)
所以如果你是要用 live , 我会建议你乾脆在一开始载入的时候就绑好,
不需要等特定时间点再来进行绑定.
简单来说:
想要在特定时间点针对特定条件元素绑定 -> click
如果是想要针对某些会不确定的一直异动的特殊条件元素绑定 -> live click
把 live 跟 click 误混着用很容易发生这种事情...
把整个 js 在这段期间内到底干了什麽事 ,
用firebug breakpoint 一步一步去 trace 会了解更多 .
--
I am a person, and I am always thinking .
Thinking in love , Thinking in life ,
Thinking in why , Thinking in worth.
I can't believe any of what ,
I am just thinking then thinking ,
but worst of all , most of mine is thinking not actioning...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 116.59.145.191
※ 编辑: TonyQ 来自: 116.59.145.191 (04/18 10:55)
1F:推 rexkimta:谢啦,我本来是用click的,後来发现之後会新增一些card 04/18 14:20
2F:→ rexkimta:看了这篇才知道可以不用写在callback里。 04/18 14:21