社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Jquery

当我将jQuery对象作为参数传递给函数时,它会发生什么情况?

William Hammond Knight III • 5 年前 • 183 次点击  

所以我的问题是findNextSlide函数返回的是未定义的。我已经把每一步都记录下来了,当我记录下来的时候,一切都像预期的那样工作。我在浏览器中也使用了断点进行了调试,但无法判断是什么导致它返回未定义。

所有这些都是在单击缩略图时调用的,即 <a> 有一类 '.icon' . 我正在检查DOM中下一个缩略图图像的父级是否显示:无,如果是,我正在将下一张幻灯片设置为隐藏图像后面的幻灯片,然后再次调用findNextSlide函数,以确保后面的图像不被隐藏,然后获取该幻灯片的基础URL并返回它。

也许我对jQuery有一些基本的误解。当我在“$currentSlide”传入函数之前记录它时,它将作为jQuery对象记录,但是当我在它传入findNextSlide函数之后记录它时,它将作为[object object]记录。

var $currentSlide = $(this).parent();

function isSlideHidden(nextSlide) {
  return (nextSlide.css("display") === 'none')
}

function findNextSlide(currentSlide) {
  var $nextSlide = currentSlide.next().next();

  if (isSlideHidden($nextSlide)) {            
    var $newSlide = $nextSlide.next().next();

    findNextSlide($newSlide);
   }
   else {
     var $nextSlideUrl = $nextSlide.children('.icon').attr('href')
   }

   return $nextSlideUrl;
}
<section class="work__grid clearfix wrapper" style="position: relative; height: 3285px;">
    <article class="grid__sizer"></article>
    <article class="grid__item  b2b featured marketing-communications  " style="background-image: url(&quot;//localhost:3000/app/uploads/2017/04/Square-Tiles_Verity_marketing.jpg&quot;); position: absolute; left: 1.33333%; top: 0px;">
        <a href="//localhost:3000/project/verity-2/" class="icon">
            <section class="grid__caption">
                <h3 class="grid__title">Verity</h3>
                <p class="grid__copy">Guiding&nbsp;healthcare providers and patients through&nbsp;340B saving and compliance</p>
            </section>
        </a>
    </article>

    <section class="grid__item mobile__case-copy" style="background: none; position: absolute; display: none;">
        <h3 class="grid__title">Verity</h3>
        <p class="grid__copy">Guiding&nbsp;healthcare providers and patients through&nbsp;340B saving and compliance</p>
    </section>

    <article class="grid__item grid__item--wide consumer digital-experience featured leisure  " style="background-image: url(&quot;//localhost:3000/app/uploads/2018/01/2-Wide-Tiles_JuicyCafe.jpg&quot;); position: absolute; left: 33.8333%; top: 0px;">
        <a href="//localhost:3000/project/juicy-cafe/" class="icon">
            <section class="grid__caption">
                <h3 class="grid__title">Juicy Café</h3>
                <p class="grid__copy">Fueling the body and soul</p>
            </section>
        </a>
    </article>

    <section class="grid__item mobile__case-copy" style="background: none; position: absolute; display: none;">
        <h3 class="grid__title">Juicy Café</h3>
        <p class="grid__copy">Fueling the body and soul</p>
    </section>
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52882
 
183 次点击