<div class="codetitle"> <span><a style="CURSOR: pointer" data="70252" class="copybut" id="copybut70252" onclick="doCopy('code70252')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code70252"> <br> <br> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br><title>无标题文档</title> <br><script type="text/javascript" src="http://s.juzheke.com/min/f=@public/js/jquery.v1.7.js"></script> <br><script type="text/javascript"> <BR>$(function(){ <BR>$.fn.extend({ <BR>"changeTips":function(value){ <BR>value = $.extend({ <BR>divTip:"" <BR>},value) <br><br>var $this = $(this); <BR>var indexLi = 0; <br><br>//点击document隐藏下拉层 <BR>$(document).click(function(event){ <BR>if($(event.target).attr("class") == value.divTip || $(event.target).is("li")){ <BR>var liVal = $(event.target).text(); <BR>$this.val(liVal); <BR>blus(); <BR>}else{ <BR>blus(); <BR>} <BR>}) <br><br>//隐藏下拉层 <BR>function blus(){ <BR>$(value.divTip).hide(); <BR>} <br><br>//键盘上下执行的函数 <BR>function keychang(up){ <BR>if(up == "up"){ <BR>if(indexLi == 1){ <BR>indexLi = $(value.divTip).children().length-1; <BR>}else{ <BR>indexLi--; <BR>} <BR>}else{ <BR>if(indexLi == $(value.divTip).children().length-1){ <BR>indexLi = 1; <BR>}else{ <BR>indexLi++; <BR>} <BR>} <BR>$(value.divTip).children().eq(indexLi).addClass("active").siblings().removeClass(); <BR>} <br><br>//值发生改变时 <BR>function valChange(){ <BR>var tex = $this.val();//输入框的值 <BR>var fronts = "";//存放含有“@”之前的字符串 <BR>var af = /@/; <BR>var regMail = new RegExp(tex.substring(tex.indexOf("@")));//有“@”之后的字符串,注意正则字面量方法,是不能用变量的。所以这里用的是new方式。 <br><br><BR>//让提示层显示,并对里面的LI遍历 <BR>if($this.val()==""){ <BR>blus(); <BR>}else{ <BR>$(value.divTip). <BR>show(). <BR>children(). <BR>each(function(index) { <BR>var valAttr = $(this).attr("email"); <BR>if(index==1){$(this).text(tex).addClass("active").siblings().removeClass();} <BR>//索引值大于1的LI元素进处处理 <BR>if(index>1){ <BR>//当输入的值有“@”的时候 <BR>if(af.test(tex)){ <BR>//如果含有“@”就截取输入框这个符号之前的字符串 <BR>fronts = tex.substring(tex.indexOf("@"),0); <BR>$(this).text(fronts+valAttr); <BR>//判断输入的值“@”之后的值,是否含有和LI的email属性 <BR>if(regMail.test($(this).attr("email"))){ <BR>$(this).show(); <BR>}else{ <BR>if(index>1){ <BR>$(this).hide(); <BR>} <BR>} <br><br>} <BR>//当输入的值没有“@”的时候 <BR>else{ <BR>$(this).text(tex+valAttr); <BR>} <BR>} <BR>}) <BR>} <BR>} <br><br><BR>//输入框值发生改变的时候执行函数,这里的事件用判断处理浏览器兼容性; <BR>if($.browser.msie){ <BR>$(this).bind("propertychange",function(){ <BR>valChange(); <BR>}) <BR>}else{ <BR>$(this).bind("input",function(){ <BR>valChange(); <BR>}) <BR>} <br><br><BR>//鼠标点击和悬停LI <BR>$(value.divTip).children(). <BR>hover(function(){ <BR>indexLi = $(this).index();//获取当前鼠标悬停时的LI索引值; <BR>if($(this).index()!=0){ <BR>$(this).addClass("active").siblings().removeClass(); <BR>} <BR>}) <br><br><BR>//按键盘的上下移动LI的背景色 <BR>$this.keydown(function(event){ <BR>if(event.which == 38){//向上 <BR>keychang("up") <BR>}else if(event.which == 40){//向下 <BR>keychang() <BR>}else if(event.which == 13){ //回车 <BR>var liVal = $(value.divTip).children().eq(indexLi).text(); <BR>$this.val(liVal); <BR>blus(); <BR>} <BR>}) <BR>} <BR>}) <br><br><BR>$("#loginName").changeTips({ <BR>divTip:".on_changes" <BR>}); <BR>}) <BR></script> <br><style type="text/css"> <BR>*{margin:0;padding:0;} <br><br>.login{width:400px; margin:0 auto; background:#EBEBEB; position:relative;} <br><br>input{ width:230px; height:28px; margin:10px 0; line-height:28px;} <br><br>.login .on_changes{width:232px; position:absolute; top:40px; list-style:none; background:#FFF; border:1px solid #000; display:none; padding:10px;} <br><br>.login .on_changes li{margin:8px;padding:4px;} <br><br>.login .on_changes li.active{ background:#CEE7FF;} <br><br></style> <br> <br> <br><div class="login"> <br><div class="ln"><input type="text" maxlength="128" name="loginName" id="loginName" placeholder="邮箱/会员帐号/手机号"></div> <br><ul class="on_changes"> <br><li email="">请选择邮箱类型</li> <br><li email=""> <br><li email="@sina.com"> <br><li email="@163.com"> <br><li email="@qq.com"> <br><li email="@hotmail.com"> <br><li email="@126.com"> <br><li email="@gmail.com"> <br><li email="@yahoo.com"> <br> </ul> <br> </div> <br> <br> </div>