“Next” button appearing when shouldn't

有些话、适合烂在心里 提交于 2019-12-25 04:26:36

问题


I'm have a function, below, that is comparing the text in two selectors. If the last occurrence of both of these selectors is the same, the "next" button will disappear. Currently, this is not working. I'm not sure why this is happening. Just fyi, what I'm trying to select is a schema 'itemprop' and is somewhat atypical.

Here is the fiddle - https://jsfiddle.net/carbot3000/8qjdxsz7/3/

function showHide(){
  if ( $('#areall span[itemprop="reviewBody"]').last().text().trim() == $('.review span[itemprop="reviewBody"]:visible').last().text().trim())
   {
     $('.next').hide();
  }
  else if ($('#areaall span[itemprop="reviewBody"]').first().text().trim() == $('.review:visible span[itemprop="reviewBody"]').first().text().trim())
   {
     $('.prev').hide();
  }
 }

回答1:


Please change your showHide function like this.

function showHide(){
if ( $("#areaall").children().last().index() == $("#areaall .review:visible").last().index())
  {
    $('.next').hide();
  }
  else if ($("#areaall").children().first().index() == $("#areaall .review:visible").first().index()) {
    $('.prev').hide();
  }
}

Refer this Updated Fiddle



来源:https://stackoverflow.com/questions/39401977/next-button-appearing-when-shouldnt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!