使用jQuery将特定符号后的文字换行 [英] Wrap text after particular symbol with jQuery

查看:423
本文介绍了使用jQuery将特定符号后的文字换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是将文本包装到ll标签内的div中.不会有问题,但是我需要包装出现在-"(减号)之后的文本,包括减号"本身.

What I'm trying to do, is wrap text into div inside ll tag. It wouldn't be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself.

这是我的html:

<ul>
    <li>Some list text - Additional text</li>
</ul>

作为结果,我正在尝试实现这一目标:

As I result I'm trying to achieve this:

<ul>
     <li>Some list text <span class="after">- Additional text<span></li>
</ul>

任何人都可以帮助我吗?

Will anyone will be able to help me please?

谢谢.

推荐答案

应该执行类似的操作.

$('li').each(function() {
  $(this).html($(this).text().replace(/-.*$/, '<span class="after">$&</span>'));
});

这篇关于使用jQuery将特定符号后的文字换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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