Hiding Email Address With jQuery
I know there are plugins that do this, but I need something pretty specific and I can't find anything.
I need a jQuery script that only change the mailto
link, and not the text of the link. For example:
<a href="person(at)exammple.com">Person's Email</a>
I need to display something else inside the link besides the actual e-mail address. The script I was trying to use is from this site.
Here's the script:
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();
});
};
I think I need to replace the "email" variable with something else in between the <a>
tags, but I'm not sure with what. I'm still pretty new to开发者_StackOverflow中文版 jQuery.
Thanks.
How about this:
(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();
});
});
You can try it @ jsfiddle
var email = $(this).html().replace('@', '(at)');
I have a jq-plug-in i made that might help. See the fiddle(working demo)
Keep in mind the plugin ends at /* -------------------------------------------------------------------------- */
To use is ez:
$("#domElementID").jqMailTo({ // Not all of these options are a must except for the address
address: ["Saab@test.net","Volvo@test.net","BMW@test.net"], // can also be as simple as 1 string, exp -> address:'BMW@test.net',
label: 'testLabel',
subject: 'This is a subject',
body: 'This is a Body section',
cc: 'aCC@test.net',
bcc: 'theBCC@test.com'
});
精彩评论