js为微博内容添加话题及人员链接

由于做的是手机网站,所以链接为链接到微博手机站

这里主要用到了js的replace方法,具体如下

var text = weibo.text.replace(/#[^#]*#/g, function(data) {
            return "<a href='http://m.weibo.cn/k/"
               + data.replace(/#/g, "")
               + "' target=_blank  >"
               + data + "</a>"
        });
text = text.replace(/@[^\s]*\s|@[^\s]*$/g, function(data) {
            return "<a href='http://m.weibo.cn/n/"
            + data.replace(/@/g, "")
            + "'  target=_blank >"
            + data + "</a>"
        });

你可能感兴趣的:(js为微博内容添加话题及人员链接)