jquery - 使用 jQuery 隐藏电子邮件地址

标签 jquery email

我知道有一些插件可以做到这一点,但我需要一些非常具体的东西,但我找不到任何东西。

我需要一个仅更改 mailto 的 jQuery 脚本链接,而不是链接的文本。例如:

<a href="person(at)exammple.com">Person's Email</a>

除了实际的电子邮件地址之外,我还需要在链接中显示其他内容。我试图使用的脚本来自 this site .

这是脚本:

jQuery.fn.mailto = function() {
    return this.each(function(){
        var email = $(this).html().replace(/\s*\(.+\)\s*/, "@");
        $(this).before('<a href="mailto:' + email + '" rel="nofollow" title="Email ' + email + '">' + email + '</a>').remove();
    });
};

我想我需要将“email”变量替换为 <a> 之间的其他内容标签,但我不确定用什么标签。我对 jQuery 还是很陌生。

谢谢。

最佳答案

这个怎么样:

(function($) {
    jQuery.fn.mailto = function() {
        return this.each(function() {
            var email_add = $(this).attr("href").replace(/\s*\(.+\)\s*/, "@");
            var email_text = $(this).html();
            $(this).before('<a href="mailto:' + email_add + '" rel="nofollow" title="Email ' + email_add + '">' + email_text + '</a>').remove();
        });
    };

})(jQuery);

$(document).ready(function() {
    $(function() {
        $('.email').mailto();
    });
});

你可以试试@jsfiddle

关于jquery - 使用 jQuery 隐藏电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7489640/

相关文章:

php - 通过PHP向许多用户发送邮件的安全方法

jquery - jQuery 可以监听浏览器事件吗?

javascript - jQuery Selectbox append 选项 OnChange

javascript - 如何在ajax进程完成之前创建延迟?

perl - 为什么 Perl 的 MIME::Lite 失败并显示 "SMTP data() command failed: 2.1.5 ... Recipient ok"?

c# - 通过电子邮件整合两个系统

php - 使用PHP脚本、MySQL数据库发送群发邮件

JavaScript 一次切换一个

javascript - 由于所有行名称都相同,如何获取 php 中的行值?

python - 字符串格式的电子邮件的有效负载,python