0
以下是我的代码。JavaScript regexr用html替换字符串?
var input = "this is @renish profile";
var matches = input.replace(/(@\w*)/g,'<a href="http://example.com/users/profile/$1">$1</a>');
的输出是:
this is <a href="http://example.com/users/profile/@renish">@renish</a> profile
这是打印HTML代码。如何从字符串转换标签?
你到底想达到什么目的? – gipadm
如果您使用的是jQuery,您可以使用jQuery.parseHTML()http://api.jquery.com/jquery.parsehtml/ –
您现在如何将该字符串添加到页面中......这是$ 1,000的问题。 – epascarello