我正在使用此脚本对字符串结果进行编号,但我想使用字母而不是数字,我该怎么做?
<span id="posicao"></span>
// numera questões
$("*[id*=posicao]").each(function(index) {
$(this).append("Questão " + (index + 1));
});
例如:
勾选一个水果:
1. Car
2. ball
2. orange
4. cell
我想要:
A. Car
B. ball
C. orange
D. cell
最佳答案
您应该在 HTML 中使用列表。您可以使用有序列表,将 span
替换为 li
并设置 list-style-type
样式,如下所示:
ol {
list-style-type: upper-latin;
}
<ol>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
</ol>
没有必要用 JS 使任何事情变得过于复杂。
关于javascript - 使用javascript对结果进行编号时如何用字母代替数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59250645/