我想将这种代码包含在第二位.
<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>
Run Code Online (Sandbox Code Playgroud)
因为可用的宽度我想替换 用<br/>.
这是我当前的代码,但它不起作用:
$( " " ).replaceWith( "<br/>" );
Run Code Online (Sandbox Code Playgroud)
干得好:
$('#social-links').html($('#social-links').html().replace(/ /g,"<br/>"));
Run Code Online (Sandbox Code Playgroud)
更新:
现在我在3年后再次考虑它,我会这样做:
const $socialLinks = $('#social-links');
$socialLinks.html($socialLinks.html().split(' ').join('<br/>'));
Run Code Online (Sandbox Code Playgroud)
它比以前的代码具有更好的性能.