我有一个句子/H1,我需要将其拆分,使其如下所示
原始状态
<h1>This is the heading </h1>
之后
<h1>This <br>
is <br>
the <br>
heading </h1>
最佳答案
我建议:
$('h1').each(
function(){
var that = $(this),
newText = that.text().replace(/\W/g,'<br />');
that.html(newText);
});
引用文献:
- jQuery 引用资料:
- JavaScript 引用:
关于jquery - 使用 jQuery 将句子/字符串拆分为单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10572836/