thymeleaf - 在电子邮件 ID 中查找并替换到 thymleaf 中的 mailto 链接
问题描述
我想知道 thymleaf 模板中的电子邮件 ID 到 mailto 链接,例如:hello@gmail.com 到<a href="mailto:hello@gmail.com"></a>
它应该使用正则表达式来查找电子邮件 ID。
我曾尝试使用 thymleaf 内联 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>
如果没有直接的方法可以做到这一点,如何做到这一点?提前致谢。
解决方案
推荐阅读
- flutter - 如何将过期时间添加到颤动的 Web cookie?
- python - 如何将不同长度和形状的数组相乘?
- haskell - Reflex-FRP 中的计数器小部件
- python - 列表理解 Python 嵌套
- javascript - 如何根据数字和字符串(阿拉伯语名称)对对象数组进行排序?
- c - C - 将全局复制到本地数组,而不是分配索引
- java - Twofish encryption decryption Algorithm
- spring-boot - Spring Boot RestController DELETE 请求失败,没有 .csrf().disable()
- excel - VBA Excel 将日期单元格与 Outlook 日历事件同步
- csv - IMPORTDATA() 不提取最新数据