Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在刚刚插入的HTML中找不到类jQuery的元素_Javascript_Jquery_Backbone.js_Underscore.js - Fatal编程技术网

Javascript 在刚刚插入的HTML中找不到类jQuery的元素

Javascript 在刚刚插入的HTML中找不到类jQuery的元素,javascript,jquery,backbone.js,underscore.js,Javascript,Jquery,Backbone.js,Underscore.js,tmpl['video-list']({videos:json})是下划线模板,包含DIVs中的项目列表这里是返回示例 render:function () { var self = this; $.ajax({url:'/db/list.json', dataType:'JSON'}).done(function (json) { var html = tmpl['video-list']({videos:json}); self.$el.htm

tmpl['video-list']({videos:json})
是下划线模板,包含
DIV
s中的项目列表这里是返回示例

render:function () {
    var self = this;
    $.ajax({url:'/db/list.json', dataType:'JSON'}).done(function (json) {
        var html = tmpl['video-list']({videos:json});
        self.$el.html(html);
    });

    console.log($('.video-thumb-box'));

    $.each($('.video-thumb-box'), function(){
        console.log(this);
        $(this).bind('mouseenter', function(){
            console.log($('.video-thumb-info', this));
        });
    });
}


为什么我在
$('.video thumb box')
中找不到任何东西?

您的每个循环都是反向的

<div class="span3">
    <a href="#/video/123">
        <div class="video-thumb-box">
            <img class="video-thumb-img" src="test" alt="Video tumbnail">
            <div class="video-thumb-info hide">
                <img class="pull-right" width="16" height="16" src="/img/icons/namba.png">
                something
            </div>
        </div>
    </a>
</div>
<div class="span3">
    <a href="#/video/123">
        <div class="video-thumb-box">
            <img class="video-thumb-img" src="test" alt="Video tumbnail">
            <div class="video-thumb-info hide">
                <img class="pull-right" width="16" height="16" src="/img/icons/namba.png">
                something
            </div>
        </div>
    </a>
</div>

这是jQuery
.each()
页面

您需要再次调用
.render
$。ajax
是异步的。您需要在Ajax调用完成后执行循环。(例如,将代码移动到
done
中的功能块中。这正是问题的原因。我刚刚移动了
$。每个
都移动到
done()
中,现在一切正常。
$('.video-thumb-box').each(function() {
    console.log(this);
    $(this).bind('mouseenter', function(){
        console.log($('.video-thumb-info', this));
    });
});