Jquery用html替换字符串中的空格<br/>标签 [英] Jquery Replacing space in string with html <br /> tag

查看:72
本文介绍了Jquery用html替换字符串中的空格<br/>标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 html <br/> 标签替换字符串中的空格,最好的方法是什么?目前我有这个代码用-"替换空格.

I want to replace spaces in a string with a html <br /> tag, whats the best way of doing this?. Currently I have this code which replaces the spaces with a "-".

$(".msn").each(function() {
    $(this).text($(this).text().replace(/ /g, '-'));
});

推荐答案

$(".msn").html(function(i, oldHTML) {
    return oldHTML.replace(/ /g, '<br/>');
});

这篇关于Jquery用html替换字符串中的空格&lt;br/&gt;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆