在< li>< / li>之间将特定文字换成其他样式before textual colon“:”? [英] Wrap different style to specific text between <li></li> before textual colon ":"?

查看:130
本文介绍了在< li>< / li>之间将特定文字换成其他样式before textual colon“:”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我用言语来解释我的意思之前,这里是我想要实现的一个例子。

Before I lose myself in words trying to explain what I mean, here's an example of what I'd like to achieve.

现在:

<ul>
<li>My name: Sietse</li>
<li>Country: The Netherlands</li>
</ul>

我希望如何: b
$ b

How I'd like it to be:

<ul>
<li><strong>My name:</strong> Sietse</li>
<li><strong>Country:</strong> The Netherlands</li>
</ul>

我的网站上有很多现有内容,像第一个示例一样被标记,有一种方法来动态选择和风格化文本,直到LI中的冒号(可能包括),如第二个示例中所示?

There is a lot of existing content on my website that is marked up like the first example, but is there a way to dynamically select and style the text until the (possibly including) the colon in the LI, as displayed in the second example?

请注意, jQuery中的绝对初学者或任何Javascript。

Please note that I'm an absolute beginner in jQuery or any Javascript for that matter.

提前感谢。

推荐答案

=http://api.jquery.com/html/ =nofollow>。html()和字符串 replace() like

You can use .html() and string replace() like

$('ul li').html(function (i, html) {
    return html.replace(/(.*?:)/, '<strong>$1</strong>')
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<ul>
    <li>My name: Sietse</li>
    <li>Country: The Netherlands</li>
</ul>

这篇关于在&lt; li&gt;&lt; / li&gt;之间将特定文字换成其他样式before textual colon“:”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆