我知道有一些插件可以做到这一点,但我需要一些非常具体的东西,但我找不到任何东西。
我需要一个仅更改 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/