【问题标题】:Hide list numbering when a list's id is hidden隐藏列表的 id 时隐藏列表编号
【发布时间】:2015-10-29 09:32:34
【问题描述】:

我希望列表编号与其中的文本一起隐藏。

电流输出:

1.Two

2.Three

期望的输出:

2.Two 

3.Three

代码:

var element = document.getElementById("one");
element.style.display = 'none';
<ol>
  <li id="one">
    One
  </li>
  <li id="two">
    Two
  </li>
  <li id="three">
    Three
  </li>
</ol>

【问题讨论】:

  • 您真的想要在所需输出中包含One 元素吗?
  • 不,我的意思是不提这个。

标签: javascript html


【解决方案1】:

var element = document.getElementById("one");
element.style.display = 'none';


// we get the children to find the actual position of our element.
var list = [].slice.call(element.parentNode.children); 
// we get the current position
var curPos = list.indexOf(element);

// we set the next element to start the count from the removed one
// we don't forget that is zero based index !
list[curPos + 1].value = curPos+2;
<ol>
  <li id="one">
    One
  </li>
  <li id="two">
    Two
  </li>
  <li id="three">
    Three
  </li>
  <li id="four">
    Four
  </li>
  <li id="five">
    Five
  </li>
  
</ol>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多