微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

查找并替换电子邮件ID以发送到thymleaf中的mailto链接

如何解决查找并替换电子邮件ID以发送到thymleaf中的mailto链接

我想知道thymleaf模板中的电子邮件ID到mailto链接 例如:[email protected]<a href="mailto:[email protected]"></a>

它应使用正则表达式查找电子邮件ID。

我已经尝试过使用百里香嵌入式JavaScript,但是不幸的是,它无法在Outlook中工作。

<script>
/*<![CDATA[*/
    function formatEmails(){
        var content=document.getElementById('content').innerHTML;       
        var regex = /\S+@\S+\.\S+/g
        var matches = [];
        var match = regex.exec(content);
        var formatedContent=content;
        while (match != null) {
            if(matches.indexOf(match[0]) === -1)matches.push(match[0]); 
            match = regex.exec(content);
        }
        matches.forEach(function(email,index){
            formatedContent=formatedContent.split(email).join('<a href="mailto:'+email+'">'+email+'</a>')
        });
        document.getElementById('content').innerHTML=formatedContent;
   }
/*]]>*/
</script>

如果没有直接的方法可以做到这一点? 预先感谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。