我知道有插件可以做到这一点,但我需要一些非常具体的东西,我找不到任何东西.
我需要一个只更改mailto链接的jQuery脚本,而不是链接的文本.例如:
<a href="person(at)exammple.com">Person's Email</a>
除了实际的电子邮件地址之外,我还需要在链接中显示其他内容.我试图使用的脚本来自这个网站.
这是脚本:
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();
});
};
Run Code Online (Sandbox Code Playgroud)
我想我需要用<a>标签之间的其他内容替换"email"变量,但我不确定是什么.我还是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();
});
});
Run Code Online (Sandbox Code Playgroud)
你可以尝试@ jsfiddle
| 归档时间: |
|
| 查看次数: |
3507 次 |
| 最近记录: |