简体   繁体   English

将标签文字换成特定字符的javascript

[英]wrap tag text up to certain character javascript

I have an auto generated list in PHP. 我在PHP中有一个自动生成的列表。

How do I wrap a span tag around characters up to and including the dash? 如何将span标签包裹在破折号之前(包括破折号)周围? I want to be able to change the number and the dash with css. 我希望能够使用CSS更改数字和破折号。 I want to target all of the list items. 我想定位所有列表项。

Eg:
1-Item
2-Item
3-Item
  1-SubItem
  2-SubItem
4-Item

CSS: CSS:

ul {
    counter-reset: item;
}
li {
    display: block;
    margin-bottom: .5em;
    margin-left: 2em;
}
li:before {
    display: inline-block;
    content: counter(item) "- ";
    counter-increment: item;
    width: 2em;
    margin-left: -2em;
}

Check out the fiddle: https://jsfiddle.net/3oho2t7v/ 查看小提琴: https : //jsfiddle.net/3oho2t7v/

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

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