4000-520-616
欢迎来到免疫在线!(蚂蚁淘生物旗下平台)  请登录 |  免费注册 |  询价篮
主营:原厂直采,平行进口,授权代理(蚂蚁淘为您服务)
咨询热线电话
4000-520-616
当前位置: 首页 > 新闻动态 >
新闻详情
currentId不能直接直接通过currentId=\"#\"+m.attr..._慕课问答
来自 : www.imooc.com/qadetail/70... 发布时间:2021-03-25
currentId不能直接直接通过currentId= # +m.attr( id 来获得呢,还非要进行遍历吗

script type=\"text/javascript\"
   $(document).ready(function () {
       $(window).scroll(function () {
           var items = $(\"#content\").find(\".item\");
           var menu = $(\"#menu\");
           var top = $(document).scrollTop();
           var currentId; //滚动条现在所在位置的item id
           items.each(function () {
               var m = $(this);
               //注意:m.offset().top代表每一个item的顶部位置
               if (top m.offset().top - 300) {
                   currentId = \"#\" + m.attr(\"id\");
               } else {
                   return false;
               }
           });

           var currentLink = menu.find(\".current\");
           if (currentId currentLink.attr(\"href\") != currentId) {
               currentLink.removeClass(\"current\");
               menu.find(\"[href=\"+currentId+\"]\").addClass(\"current\");
           }
       });
   });
/script


其中currentId为什么不能直接通过currentId=\"#\"+m.attr(\"id\");来获得呢,还非要进行遍历呢?这里的m就是this,这个this难道不能取到值吗


menu.find("[href="+currentId+"]").addClass("current"); } }); });其中currentId为什么不能直接通过currentId="#"+m.attr("id");来获得呢,还非要...JavaScriptcurrentId不能直接直接通过currentId="#"+m.attr("id");来获得呢,还非要进行遍历吗currentId不能直接直接通过currentId="#"+m.attr...

本文链接: http://mattrid.immuno-online.com/view-772286.html

发布于 : 2021-03-25 阅读(0)