jQuery选择动态生成的html而不添加事件(实时) [英] JQuery selecting dynamically generated html without adding event (with live)

查看:227
本文介绍了jQuery选择动态生成的html而不添加事件(实时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于stackoverflow的几篇文章说使用live来选择动态生成的html.但是,您需要像单击这样的事件才能使用实时直播.如果您只想使用.val或.html并更改元素而不是添加事件处理程序,该怎么办?

Several posts on stackoverflow say to use live to select dynamically generated html. However you need an event like click to use live. What do you do if you just want to use .val or .html and change the element instead of adding an event handler?

(实时解决方案: Jquery无法使用动态创建的表)

我正在通过以下方式生成代码:

I am generating code through:

$.ajax({
        url: "/JobFeed/JobFeed.php",
        type: "POST",
        dataType: "html",
        success: function(html) {
            $("#jobFeed").html(html);
        }
    });

一次生成的html看起来像这样(表单重复了几次):

The html once generated looks like this (with the form repeated several times):

<div id="jobFeed" class="contentContainer">
     <div id="jobs">
         <div class="job">
             <form class="subscription">
             </form>
         </div>
    </div>
</div>

然后我添加输入:

 $("form .subscription").html("<input ... />");

推荐答案

您可以使用名为"livequery"的插件并执行以下操作:

You can use a plugin called "livequery" and do something like this:

$(selector).livequery(function(){ 

}); 

如您所见,没有必须使用的click或其他事件.

As you can see, there is no click or other event that you must use.

插件链接: http://docs.jquery.com/Plugins/livequery

在github 上: https://github.com/brandonaaron/livequery

希望这会有所帮助:-)

Hope this helps :-)

这篇关于jQuery选择动态生成的html而不添加事件(实时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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