简体   繁体   English

如何取得清单项目( <li> )以列表样式类型声明的标记/标签?

[英]How to get list item (<li>) marker/label declared in list-style-type?

Lets say I have a list like this: 可以说我有一个这样的列表:

<ul style="list-style-type: upper-latin;">
  <li>Lorem</li>
  <li>Ipsum</li>
</ul>

( list-style-type might be anything - upper-roman, katakana, lower-greek) list-style-type可以是任何东西-上罗马,片假名,下希腊)

list-style-type: upper-latin; will put a alphabet letter (starting from A) in front of every list item. 将在每个列表项的前面放置一个字母(从A开头)。 Is there a way to get this letter for any given list item? 有没有办法为任何给定的清单项目获得这封信? I can probably iterate over list using jQuery .index() or similar. 我可能可以使用jQuery .index()或类似方法遍历列表。

Or, maybe there is way to extract markers from style? 或者,也许有办法从样式中提取标记?

The answer here works only for Latin alphabet lists. 答案在这里仅适用于拉丁字母表。

Is there a way to get this letter for any given list item? 有没有办法为任何给定的清单项目获得这封信?

Yes. 是。 You can read the list-style-type and generate what characters are showing for each style type. 您可以阅读list-style-type并生成每种样式类型显示的字符。 Which character is shown for a specific item number and style type could vary across browsers though. 但是,针对特定商品编号和样式类型显示的字符可能会因浏览器而异。

Or, maybe there is way to extract markers from style? 或者,也许有办法从样式中提取标记?

No. (At least not currently) 否(至少目前不是)

Some useful stuff for writing a generator: 编写生成器的一些有用的东西:

Also, many of the list-styles are uppercase versions of other list styles. 同样,许多列表样式是其他列表样式的大写版本。 Could be good to know then that myString.toUpperCase() works on unicode characters as well. 可能很高兴知道myString.toUpperCase()适用于Unicode字符。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM