替换 nbsp;<br/> [英] Replace nbsp; with <br/>
本文介绍了替换 nbsp;<br/>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想把这种代码放在第二位.
由于可用宽度,我想用 <br/>
替换
.
这是我当前的代码,但它不起作用:
$( " " ).replaceWith( "<br/>" );
解决方案
给你:
$('#social-links').html($('#social-links').html().replace(/ /g,"<br/>"));
更新:
现在我在 3 年后再次考虑它,我会这样做:
const $socialLinks = $('#social-links');$socialLinks.html($socialLinks.html().split(' ').join('<br/>'));
它的性能比之前的代码好很多.
I want to include this kind of code to a second place.
<div id="social-links">
<!-- Facebook -->
<a href="https://www.facebook.com/name" target="_blank">
<i class="fa fa-facebook-square fa-lg"></i>
Facebook
</a>
<!-- Google+ -->
<a href="https://plus.google.com/+name" target="_blank">
<i class="fa fa-google-plus fa-lg"></i>
Google+
</a>
</div>
Because of the available width I want to replace the
with <br/>
.
This is my current code but it doesn't work:
$( " " ).replaceWith( "<br/>" );
解决方案
here you go:
$('#social-links').html($('#social-links').html().replace(/ /g,"<br/>"));
UPDATE:
Now that I think about it again after 3 years, I'd do it this way:
const $socialLinks = $('#social-links');
$socialLinks.html($socialLinks.html().split(' ').join('<br/>'));
It has much better performance than the previous code.
这篇关于替换 nbsp;&lt;br/>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文