0

我将不得不重新发布我之前的问题,因为我需要重新制定我需要的内容。

所以,就这样吧。

我有一个包含一些列表项的网页,

HTML

<div class="container">
<p>Items are ordered Alphabetically and I want the text to be untouched</p>
</div>

所有这些列表项都包含在我计算机上的一个文件夹中。我想要做的不是手动输入 ../Html/1.html , ../Html/2.html, ... 相反,我希望找到一个脚本来为我完成这项工作。

所有项目都按数字顺序编号,从 1 一直到 100。所以我知道使用 i++ 进行迭代可能会在循环中派上用场。但我真的不知道更多!

4

1 回答 1

2

用这个:

<div id="theContainer" class="container">
  <p>Items are ordered Alphabetically and I want the text to be untouched</p>
</div>

<script>
window.addEventListener('DOMContentLoaded', function() {
  var container = document.getElementById('theContainer'), i, p, s;
  var numStart = 1, numEnd = 100;
  var path = '../Html/*.html'; //use "*" to substitute the number
  for (i = numStart; i <= numEnd; i++) {
    p = path.replace(/\*/,i);
    s += '<li><a href="' + encodeURI(p) + '">' + p + '</a></li>';
  }
  container.innerHTML = container.innerHTML + '<ol>' + s + '</ol>';
}, false);
</script>
于 2012-10-26T19:43:43.670 回答