在使用jQuery由ajax生成后如何执行另一个动作? [英] How to execute another action after generated by ajax with jQuery?

查看:55
本文介绍了在使用jQuery由ajax生成后如何执行另一个动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此ajax函数与jquery一起使用. ( http://pastie.org/798788 )

I have this ajax function with jquery. (http://pastie.org/798788)

输出如下.

<div class="content">
    <h1>Latest Messages or Task To Do</h1>

    <ul style="display: block;" id="message_ul">
    <li class="86">
<div class="listbox"><span class="user">
<strong>Administrator</strong></span>
<span class="date">2010-01-28 08:57:43</span>
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/86"
class="todo">to do</a>
<span class="msg">Change links in message, to do, completed 
and delete to anchor </span>
</div>
   </li>

<li class="85">
<div class="listbox"><span class="user">
<strong>Administrator</strong></span>
<span class="date">2010-01-28 08:51:15</span>
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/85"
class="todo">to do</a>
<span class="msg"> meta tag keywords and 
description should show from page input/database </span>
</div>
</li>

<li class="84">
...
...

现在,我正在尝试使用class ="todo"添加另一个ajax.但是,当我尝试此进行测试时.它不会警报.它执行php函数.

Now I am trying to add another ajax with class="todo". However when I tried this for testing. It does not alert. It executes the php function.

$(".todo").click(function(){
    event.preventDefault();
    alert("hei");

}); 

我不确定为什么.是因为它是由ajax创建的吗?

I am not sure why. Is it because it is created by ajax?

与绑定有关吗?我该如何运作?

Is it something to do with binding? How can I make it work?

我正在使用CodeIgniter.

I am using CodeIgniter.

其他 php函数在此处. (http://pastie.org/798802)

推荐答案

您似乎需要使用

It looks like you need to be using the live-style event binding and name the event object as a parameter to the click handler.

$(".todo").live('click', function(event) {
    event.preventDefault();
    ...
});

这篇关于在使用jQuery由ajax生成后如何执行另一个动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆