用破折号JavaScript替换空间 [英] replace space with dash JavaScript
本文介绍了用破折号JavaScript替换空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var html = "<div>"+title+"<br/>";
document.write(title.replace(/ /g,"-"));
html+= '<p><a href="go.aspx?title=' + title + '">Details<\/a></p></div>';
我想用破折号替换标题空格。
I want to replace title space with dash.
推荐答案
尝试 title.replace(/ \s / g, - )
。 ( / \s /
是空白的正则表达式转义)。
Try title.replace(/\s/g , "-")
instead. (/\s/
is the regex escape for whitespace).
此外,请执行:
title = title.replace(/\s/g , "-");
var html = "<div>" + title + "</div>";
// ...
这篇关于用破折号JavaScript替换空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文