替换富文本中的a标签跳转

var str = '<a href="https://baike.baidu.com/item/%E7%B4%A2%E7%A6%8F%E5%85%8B%E5%8B%92%E6%96%AF" target="_blank"><u><font color="#0066cc">索福克勒斯</font></u></a><a href="https://baike.baidu.com/item/%E6%88%8F%E5%89%A7%E6%83%85%E6%99%AF" target="_blank"><u><font color="#0066cc">戏剧情景</font></u></a><a href="https://baike.baidu.com/item/%E6%9D%A8%E9%97%A8%E5%A5%B3%E5%B0%86" target="_blank"><u><font color="#0066cc">杨门女将</font></u></a>'

var regs1 = new RegExp(/href="(.*?)"/,'gi');
str = str.replace(regs1, "onclick=\"go('$1')\"");
console.log(str);

<a onclick="go('https://baike.baidu.com/item/%E7%B4%A2%E7%A6%8F%E5%85%8B%E5%8B%92%E6%96%AF')" target="_blank"><u><font color="#0066cc">索福克勒斯</font></u></a><a onclick="go('https://baike.baidu.com/item/%E6%88%8F%E5%89%A7%E6%83%85%E6%99%AF')" target="_blank"><u><font color="#0066cc">戏剧情景</font></u></a><a onclick="go('https://baike.baidu.com/item/%E6%9D%A8%E9%97%A8%E5%A5%B3%E5%B0%86')" target="_blank"><u><font color="#0066cc">杨门女将</font></u></a>

 

posted @ 2019-10-18 15:19  枫叶红~  阅读(1739)  评论(0编辑  收藏  举报