如何将每个文本行换成span?
从这段代码:
<p>
jkhkjh kjhjh jkhj
hghghjg hjg hj gh
hghkj jk kk
</p>
期望的结果:
<p>
<span>jkhkjh kjhjh jkhj</span>
<span>hghghjg hjg hj gh</span>
<span>hghkj jk kk</span>
</p>
答案 0 :(得分:0)
vanilla JS
var p = document.getElementsByTagName('p')[0];
p.innerHTML = '<span>' + p.innerHTML.split('\n').join('</span><span>') + '</span>';