将SPAN包裹在DIV中的所有数字中 [英] Wrap SPAN around all numbers in a DIV

查看:158
本文介绍了将SPAN包裹在DIV中的所有数字中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个div中包围所有数字,所以我可以相应地设计它们的样式。

I am trying to wrap a span around all numbers in a div so I can style them accordingly.

我已经搜索了一些javascript来完成此操作,但没有能够将div中的所有数字作为目标。

I have searched for some javascript to do this with no luck on being able to target all the numbers within the div.

圣经经文将被复制并粘贴到textarea中。我想对其中的所有数字进行样式设置。与此网站的用法类似: http://marshill.com/media/trial / trial-and-jesus#scripture

It will be for Bible verses that will be copied and pasted into a textarea. I would like to style all of the numbers within that. Similar to how this site does here: http://marshill.com/media/trial/trial-and-jesus#scripture

在圣经选项卡下。

Under the "Scripture" tab.

推荐答案

这里:

Here:

elem.innerHTML = elem.innerHTML.replace( /\b(\d+)\b/g, '<span>$1</span>' );

现场演示: http://jsfiddle.net/ujA86/

这篇关于将SPAN包裹在DIV中的所有数字中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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