根据验证邮箱的域名跳转到相应的登录页面 发表于 2017-06-29 | 分类于 前端学习 | 阅读次数 | 之前由于公司项目要求,需要根据邮箱跳转到对应的邮箱,百度了半天才找到一个,不多说直接帖代码123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051<!DOCTYPE HTML><html><head><meta charset="utf-8"><title>js邮箱地址跳转</title><script type="text/javascript" src="jquery.js"></script><script type="text/javascript">var hash={'qq.com': 'http://mail.qq.com','gmail.com': 'http://mail.google.com','sina.com': 'http://mail.sina.com.cn','163.com': 'http://mail.163.com','126.com': 'http://mail.126.com','yeah.net': 'http://www.yeah.net/','sohu.com': 'http://mail.sohu.com/','tom.com': 'http://mail.tom.com/','sogou.com': 'http://mail.sogou.com/','139.com': 'http://mail.10086.cn/','hotmail.com': 'http://www.hotmail.com','live.com': 'http://login.live.com/','live.cn': 'http://login.live.cn/','live.com.cn': 'http://login.live.com.cn','189.com': 'http://webmail16.189.cn/webmail/','yahoo.com.cn': 'http://mail.cn.yahoo.com/','yahoo.cn': 'http://mail.cn.yahoo.com/','eyou.com': 'http://www.eyou.com/','21cn.com': 'http://mail.21cn.com/','188.com': 'http://www.188.com/','foxmail.coom': 'http://www.foxmail.com'}; $(function(){$(".mail").each(function() {var url = $(this).text().split('@')[1];for (var j in hash){$(this).attr("href", hash[url]);}});})</script></head> <body><a href="#" target="_blank" class="mail"><a href="mailto:laike@qq.com">laike@qq.com</a></a> <br><a href="#" target="_blank" class="mail"><a href="mailto:laike@gmail.com">laike@gmail.com</a></a> <br><a href="#" target="_blank" class="mail"><a href="mailto:laike@sina.com">laike@sina.com</a></a> <br><a href="#" target="_blank" class="mail"><a href="mailto:laike@163.com">laike@163.com</a></a> <br><a href="#" target="_blank" class="mail"><a href="mailto:laike@souhu.com">laike@souhu.com</a></a> <br><a href="#" target="_blank" class="mail"><a href="mailto:laike@hotmail.com">laike@hotmail.com</a></a></body></html> 之后,有大神帮忙优化调整了一下,还是那句话,直接上代码1234567891011121314151617181920212223242526272829303132333435<input type="text" class="txt" /><a href="javascript:" class="submit">立即前往邮箱</a><script src="http://libs.useso.com/js/jquery/1.10.0/jquery.min.js"></script><script>var hash = { 'qq.com': 'http://mail.qq.com', 'gmail.com': 'http://mail.google.com', 'sina.com': 'http://mail.sina.com.cn', '163.com': 'http://mail.163.com', '126.com': 'http://mail.126.com', 'yeah.net': 'http://www.yeah.net/', 'sohu.com': 'http://mail.sohu.com/', 'tom.com': 'http://mail.tom.com/', 'sogou.com': 'http://mail.sogou.com/', '139.com': 'http://mail.10086.cn/', 'hotmail.com': 'http://www.hotmail.com', 'live.com': 'http://login.live.com/', 'live.cn': 'http://login.live.cn/', 'live.com.cn': 'http://login.live.com.cn', '189.com': 'http://webmail16.189.cn/webmail/', 'yahoo.com.cn': 'http://mail.cn.yahoo.com/', 'yahoo.cn': 'http://mail.cn.yahoo.com/', 'eyou.com': 'http://www.eyou.com/', '21cn.com': 'http://mail.21cn.com/', '188.com': 'http://www.188.com/', 'foxmail.coom': 'http://www.foxmail.com'};$('.txt').on('blur',function (){ var url = $(this).val().split('@')[1]; for (var j in hash) { $('.submit').attr("href", hash[url]); }}); </script> 希望这篇文章能够满足大家 欢迎关注本人公众号