jquery只返回第一个值

jquery只返回第一个值,jquery,Jquery,我想通过每个人,得到图像的大小。通过高度和宽度,我可以设置div“.text person show”的高度和宽度 html: "> 问题是:为什么我只收到第一个“.person”的警告(w)? 我现在不明白!变量范围 许多Thx!!!尝试下面的代码并在将来的事件中使用.on事件,同时删除每个循环 $(window).load(function () { $('.person').on('hover', function () {

我想通过每个人,得到图像的大小。通过高度和宽度,我可以设置div“.text person show”的高度和宽度

html:


">

问题是:为什么我只收到第一个“.person”的警告(w)? 我现在不明白!变量范围


许多Thx!!!

尝试下面的代码并在将来的事件中使用.on事件,同时删除每个循环

$(window).load(function () {                    
        $('.person').on('hover', function () {
        var h = $(this).find(".person-image").height();
        var w = $(this).find(".person-image").width();

            alert(w);
            $(this).find(".person-image").toggle();
            $(this).find(".text-person").toggle();
            $(this).find(".text-person").toggleClass("text-person-show", 'add');
            $(".text-person-show").width(w).height(h);
        });
       });
David Thomas建议的旁注:

on()已从版本1.7开始在jQuery中可用(此时 在1.7之前的jQuery中,jQuery团队 在方法本身的API文档中,建议使用 委托()的类型。live()存在许多问题(链接、, 事件冒泡和性能),即使在 它是可用的(除非文档中对 方法(已确认)


因为这是在集合上运行getter的预期行为;您期望/想要得到什么?每当我在循环中看到手动事件绑定时,我都会感到不舒服。我喜欢获取每个.person的值,相关的HTML在哪里?Fiddle也会很棒。也许您只有一个
。person
?在jQuery中可用在1.7之前的jQuery中,jQuery团队在方法本身的API文档中建议使用。
live()
存在许多问题(链接、事件冒泡和性能),即使在可用的地方也不应使用(除非文件中确认了该方法的权衡)。thanx@DavidThomas我已相应更新了答案
<div class="person">
<div class="person-post">
    <div class="person-image">  <img src="<?php the_field('image'); ?>"></div>
        <div class="text-person">
            <div class="text-inner">
                 <div class="name-person-text-inner"><?php the_title(); ?>
                 </div>     
            </div>
        </div>
</div>
$(window).load(function () {                    
        $('.person').on('hover', function () {
        var h = $(this).find(".person-image").height();
        var w = $(this).find(".person-image").width();

            alert(w);
            $(this).find(".person-image").toggle();
            $(this).find(".text-person").toggle();
            $(this).find(".text-person").toggleClass("text-person-show", 'add');
            $(".text-person-show").width(w).height(h);
        });
       });