微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用jquery加载gravatar

只是试图在博客上装箱一个简单的评论表单。当他/她在电子邮件箱中写入时,我想加载用户的gravatar(使用jQuery)。

我怎样才能做到这一点?

解决方法

gravatar url看起来像这样:
http://www.gravatar.com/avatar/<md5hashofemail>

Here are the rest of the options for the URL.

所以你要做的就是包括一个名为md5的函数,返回用户电子邮件的md5哈希值。有很多网路做到这一点,但我相信this one运作良好。之后,只要做

// get the email
var email = $('#email').val();
// -- maybe validate the email? 

// create a new image with the src pointing to the user's gravatar
var gravatar = $('<img>').attr({src: 'http://www.gravatar.com/avatar/' + md5(email)});
// append this new image to some div,or whatever
$('#my_whatever').append(gravatar);

// OR,simply modify the source of an image already on the page
$('#image').attr('src','http://www.gravatar.com/avatar/' + md5(email));

我以为这是显而易见的,但我会补充一下以后的缘故:

如果用户电子邮件是私人的,并且您在列表中显示此ala-stackoverflow,则可能会更好地编码服务器上的电子邮件,以便在查看源时不会公开显示用户的电子邮件

原文地址:https://www.jb51.cc/jquery/182583.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐