Javascript 如何将标签标记中的空格替换为<;br>;?
如何用Javascript 如何将标签标记中的空格替换为<;br>;?,javascript,jquery,html,Javascript,Jquery,Html,如何用替换标记中的所有空格? 例如,我有: <label>Some text here</label> 这里有一些文本 并将其更改为: <label>Some<br>text<br>here</label> 这里有一些文本 我尝试使用以下代码: $('.form-group label').html().replace(' ', '<br>'); $('.form group label').html(
替换标记中的所有空格? 例如,我有:
<label>Some text here</label>
这里有一些文本
并将其更改为:
<label>Some<br>text<br>here</label>
这里有一些
文本
我尝试使用以下代码:
$('.form-group label').html().replace(' ', '<br>');
$('.form group label').html().replace('',
');
但它不起作用。使用带有回调函数的方法。并使用全局falg-in方法替换所有的空间使用正则表达式。
$('label').html(函数(i,oldHTML){
返回oldHTML.replace(/\s+/g,
);
});代码>
此处的一些文本
您必须设置html,这可能会起作用:
$('.form-group label').html($('.form-group label').html().replace(' ', '<br>'));
$('.form group label').html($('.form group label').html().replace('',
'));
@VladIvanov:很高兴能帮你替换所有空格-只有第一个空格