Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 将不同样式换行到<;之间的特定文本;李></李>;在文本冒号“之前:&引用;?_Jquery_Css - Fatal编程技术网

Jquery 将不同样式换行到<;之间的特定文本;李></李>;在文本冒号“之前:&引用;?

Jquery 将不同样式换行到<;之间的特定文本;李></李>;在文本冒号“之前:&引用;?,jquery,css,Jquery,Css,在我试图用语言来解释我的意思之前,这里有一个我想要实现的例子 现在怎么样: <ul> <li>My name: Sietse</li> <li>Country: The Netherlands</li> </ul> <ul> <li><strong>My name:</strong> Sietse</li> <li>&l

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

现在怎么样:

<ul>
    <li>My name: Sietse</li>
    <li>Country: The Netherlands</li>
</ul>
<ul>
    <li><strong>My name:</strong> Sietse</li>
    <li><strong>Country:</strong> The Netherlands</li>
</ul>
  • 我的名字:Sietse
  • 国家:荷兰
我希望它是什么样子:

<ul>
    <li>My name: Sietse</li>
    <li>Country: The Netherlands</li>
</ul>
<ul>
    <li><strong>My name:</strong> Sietse</li>
    <li><strong>Country:</strong> The Netherlands</li>
</ul>
  • 我的名字:Sietse
  • 国家:荷兰
我的网站上有很多像第一个示例那样标记的现有内容,但是有没有一种方法可以动态选择文本并设置其样式,直到LI中出现冒号(可能包括冒号),如第二个示例所示

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

您可以使用

$('ulli').html(函数(i,html){
返回html.replace(/(.*?:)/,“$1”)
})

  • 我的名字:Sietse
  • 国家:荷兰
尝试以下内容

$(函数(){
$(“ul li”)。每个(函数(){
if($(this).text().indexOf(':')>-1){
$(this.html(“”+$(this.html().split(“:”).join(“:”);
}
});
});

  • 我的名字:Sietse
  • 国家:荷兰

如果不将文本作为元素,则无法为其设置样式。这可以通过JavaScript动态完成,但由于这更像是一种结构特性,为什么不简单地将标记更改为您想要的样子呢?或者是表格,因为这看起来更像是表格数据而不仅仅是列表。花半个小时左右的时间,在文件中查找和替换,然后修复它。而不是为每个请求动态地修补它。好吧,如果我这样做的话,我会花一整天来修复这个:)有很多内容。但请注意:Arun P Johny的解决方案会不会给我的服务器造成太大的压力?哇,非常感谢,这很有魅力,正是我所需要的!谢谢你的快速回答。然而,尽管看起来像是Arun P Johny提出的解决方案,但它似乎不是开箱即用的。我认为它针对太多的李,而不仅仅是内容文本中的那些。