使用CSS或JQuery更改特定字符的格式 [英] Change formatting of a specific character using css or jquery
问题描述
我有时会使用管道来构建快速,肮脏的html菜单或其他类型的列表.分隔元素,即:
I sometimes build quick and dirty html menus or other types of lists using a pipe | to separate elements, ie:
首页|编辑等等...
Home | edit | etc...
我喜欢使管道变为粗体和彩色,并想知道是否有一种快速的方法来选择css样式中的特定字符. (或者也许是JS/jquery)
I like to make the pipes bold and colored, and wonder if there is a quick way to select a specific character in css styles. (or maybe JS/jquery)
我确实知道我可以使用管道周围的跨距来做到这一点,但认为仅选择此字符可能会很优雅.
I do know that I can do this with spans around the pipe, but thought it might be elegant to be able to select just this character.
推荐答案
您可以将回调函数传递给 .html()
将这些字符打包为跨距的方法:
You can pass a callback function to the .html()
method to wrap those characters in spans for you:
$('p.menu').html(function(i,el) {
return el.replace(/\|/g, '<span class="sp">|</span>');
});
http://jsfiddle.net/mblase75/ymE6y/
这篇关于使用CSS或JQuery更改特定字符的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!