//去掉所有html标签 str.replace(/<[^>]*>|<\/[^>]*>/gm, ""); //保留img标签 str.replace(/<(?!img).*?>/g, ""); //保留img和p 标签 str.replace(/<(?!img|p|/p).*?>/g, "");