[removed] Ordinal suffix for numbers with specific CSS class

前端 未结 8 1551
时光说笑
时光说笑 2021-02-14 03:01

I am trying to display numbers within a particular table with ordinal suffixes. The table always shows three numbers which come from an XML file. The numbers show ranks, so for

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-14 03:12

    Ordinal suffix in one line

    var integerWithSuffix=originalInteger+(['st','nd','rd'][( originalInteger +'').match(/1?\d\b/)-1]||'th');
    

    the concatenation of the original number and a string representing the ordinal derived from an array indexed by the result of a regex search on that number

    http://jsfiddle.net/thisishardcoded/DbSMB/

提交回复
热议问题