如何进行订购列表 javascript?

假设我有这个


<ol>
<li>V1 One</li>
<li>V1 Two</li>
<li>V1 Three</li>
<li>V1 Four</li>
</ol>`


我想使用订购列表 .js 而不是使用标签
LI

.
我以为 JS. 代码可以替换第一个 V1 并称之为 1., 更换第二个 V1 并换了他两个等,换句话说,计算有多少 V1 并用有序列表替换它们。

或者可能是这样的东西


<ol>
<li>i++ V1 One</li>
<li>i++ V1 Two</li>
<li>i++ V1 Three</li>
<li>i++ V1 Four</li>
</ol>


在哪里 i++ 自从以来每次都会增加 1

是的,我知道 LI 提供有序列表!
已邀请:

八刀丁二

赞同来自:

你可能想穿过孩子们
<ol>

并操纵它们
innerHTML

?


// Get the <ol> object from the DOM
var chillun = document.getElementById/"yourOL"/.childNodes;

// Loop through the children of the <ol>
for/i=0;i<chillun.length;i++ <li="" an="" indeed="" is="" node="" test="" that="" the="" {="">
if/chillun[i].nodeName=='LI'/ {
// Change this line to manipulate the text however you need
chillun[i].innerHTML = i;
}
}


</chillun.length;i++></ol></ol></ol>

裸奔

赞同来自:

你可以空白 div 和使用 javascript 对于输入 innerHTML 里面 div


function listdown//{
var startlist = "<ol>";
var endlist = "</ol>";
*use a for loop to enter the <li>, this way, you can do much more with each item*
document.getElementById/"emptydiv"/.innerHTML = startlist + LI list + endlist;
}


EDIT

尽管如此, JQuery 仍然是最好的选择
</li>

小明明

赞同来自:

我会建议你探索 /使用/ Freyymvork. javascript 实现这一目标。 它将迅速加快您的发展 javascript. Jquery 此刻非常受欢迎,我认为你还应该使用它。 Stackoverflow allready 有一个主题 Jquery, 描述你想要的东西 =>
https://coderoad.ru/812875/

快网

赞同来自:

你可以做这样的事情:


let ol = document.querySelector/'ol'/;
let i = 1;
ol.querySelectorAll/'li'/.forEach/function/li/ {
li.textContent = /i++/ + ' ' + li.textContent;
}/;

要回复问题请先登录注册