我怎样才能获得UL中的li长度

时间:2017-02-22 07:51:51

标签: jquery html css

请检查此网址。 http://devsite.itrheat.com/products/marin-heating-systems/

我想知道的是 当您将鼠标悬停在“RV,Trailer”,“Marine Heating ..”等左侧菜单上时,您可以看到“Oasis NE”,“Oasis NE-S ......”等子菜单。

所以我想得到子菜单长度。 因为我想使子菜单宽度相同。 所以,如果我得到子菜单长度,我可以使它们的宽度相同(子菜单宽度= 100%/子菜单长度)

请帮帮我。

2 个答案:

答案 0 :(得分:0)

此代码可帮助您完成此任务。

var sublinks = document.getElementsByClassName("product-sub-links")[0];
var activeUl = sublinks.getElementsByClassName("active")[0];
var liLength = activeUl.getElementsByTagName("li").length;

答案 1 :(得分:0)

由于您通过main-id =>将主菜单映射到子菜单子类比你能做的:

import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.sentiment.*;
import edu.stanford.nlp.util.*;
import java.util.Properties;

public class SentimentExample {

  public static void main(String[] args) {
    Annotation document = new Annotation("I liked the first movie.  I hated the second movie.");
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse,sentiment");
    props.setProperty("parse.binaryTrees","true");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
    pipeline.annotate(document);
    for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
      System.out.println("---");
      System.out.println(sentence.get(CoreAnnotations.TextAnnotation.class));
      System.out.println(sentence.get(SentimentCoreAnnotations.SentimentClass.class));
    }
  }
}

确保首先显示子菜单,然后才计算宽度,因为隐藏元素(即使它被父级隐藏)将具有$('.product-top-links li').mouseenter(function () { var list = $('.product-sub-links .'+$(this).attr('id')+' li'); // total elements as "length as count of elements" console.log(list.length); var totalWidth = 0; $.each(list, function () { totalWidth += $(this).outerWidth(); }); // total width as "length as all elements combined width" console.log(totalWidth); }); 宽度