2
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));
        });
    });
}

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

<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>

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

4

1 回答 1

2

你的每个循环都是向后的。

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

这是 jQuery .each() API页面

于 2013-02-17T16:49:16.900 回答