用jQuery隐藏电子邮件地址
问题描述:
我知道有这样做的插件,但我需要一些非常具体的东西,我找不到任何东西。用jQuery隐藏电子邮件地址
我需要一个jQuery的脚本,只改变mailto
链接,而不是链接的文本。例如:
<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();
});
};
我想我需要更换与其他在<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
答
var email = $(this).html()。replace('@','(at)');
答
我有JQ-插件,我做了可能的帮助。 查看fiddle(working demo)
请记住插件在/ * --------------------------------- ----------------------------------------- */
要使用ez:
$("#domElementID").jqMailTo({ // Not all of these options are a must except for the address
address: ["[email protected]","[email protected]","[email protected]"], // can also be as simple as 1 string, exp -> address:'[email protected]',
label: 'testLabel',
subject: 'This is a subject',
body: 'This is a Body section',
cc: '[email protected]',
bcc: '[email protected]'
});
不幸的是我需要用jQuery来做到这一点。我大概可以用PHP来做,但我有具体的指示,它需要是jQuery。 – JacobTheDev
看起来像jQuery给我... –