Wrap SPAN around all numbers in a DIV(将 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.
它将用于将复制并粘贴到文本区域中的圣经经文.我想设计其中的所有数字.类似于此站点在此处的操作: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
在圣经"标签下.
推荐答案
这里:
elem.innerHTML = elem.innerHTML.replace( /(d+)/g, '<span>$1</span>' );
现场演示: http://jsfiddle.net/ujA86/
这篇关于将 SPAN 包裹在 DIV 中的所有数字周围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 SPAN 包裹在 DIV 中的所有数字周围


基础教程推荐
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01