2011-09-20 12 views
7

これを行うプラグインがあることは知っていますが、私は非常に具体的なものが必要です。何も見つかりません。jQueryで電子メールアドレスを非表示にする

リンクのテキストではなく、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(); 
    }); 
}; 

私は<a>タグの間で何か他のもので、「電子メール」の変数を交換する必要があると思うが、私は何でわかりません。私はまだjQueryの新機能です。

ありがとうございました。

答えて

8

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]' 
}); 
1

var email = $(this).html()。replace( '@'、 '(at)');あなたが、私はそれが役立つかもしれない作っJQ-プラグインを持ってjsfiddle

+0

残念ながら、jQueryを使用する必要があります。私はおそらくPHPでそれを行うことができますが、私はそれがjQueryである必要がある具体的な指示があります。 – JacobTheDev

+3

jQueryのように見えます... –

0

@それを試すことができます

(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(); 
    }); 
}); 

:これはどのように

関連する問題