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

天涯浪子 提交于 2019-12-29 05:55:47

问题


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: upper-latin; will put a alphabet letter (starting from A) in front of every list item. Is there a way to get this letter for any given list item? I can probably iterate over list using jQuery .index() or similar.

Or, maybe there is way to extract markers from style?

The answer here works only for Latin alphabet lists.


回答1:


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. 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:

  • List of Unicode characters
  • List-generator in all list-style-types
  • Numbers to roman numerals in Javascript

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. :)



来源:https://stackoverflow.com/questions/13063095/how-to-get-list-item-li-marker-label-declared-in-list-style-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!