在文本冒号“:”之前将 之间的不同样式包装到特定文本中?
在我试图解释我的意思之前,我会失去自己的语言,这是我想要实现的一个例子。
现在怎么样:
- My name: Sietse
- Country: The Netherlands
我多么喜欢它:
- My name: Sietse
- Country: The Netherlands
我的网站上有很多现有内容被标记为第一个示例,但有没有一种方法可以动态选择和设置文本样式,直到LI中的冒号(可能包括),如第二个例子中所示?
请注意,我是jQuery或任何Javascript的绝对初学者。
提前致谢。
您可以使用.html()和字符串replace()之类的
$('ul li').html(function (i, html) { return html.replace(/(.*?:)/, '$1') })
- My name: Sietse
- Country: The Netherlands
试试以下
$(function() { $("ul li").each(function() { if ($(this).text().indexOf(':') > -1) { $(this).html('' + $(this).html().split(':').join(':')); } }); });
- My name: Sietse
- Country: The Netherlands