国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery實(shí)現(xiàn)輸入框郵箱內(nèi)容自動補(bǔ)全與上下翻動顯示效果【附demo源碼下載】

2019-11-20 08:56:04
字體:
供稿:網(wǎng)友

本文實(shí)例講述了jQuery實(shí)現(xiàn)輸入框郵箱內(nèi)容自動補(bǔ)全與上下翻動顯示效果。分享給大家供大家參考,具體如下:

最近在做通行證項(xiàng)目,里面注冊模塊有郵箱注冊,需求方想要在輸入 @ 后觸發(fā)下拉框顯示各個(gè)郵箱,效果如下:

html 代碼:

<!DOCTYPE HTML><html lang="en"><head>  <meta charset="utf-8"/>  <title>郵箱自動補(bǔ)全</title>  <link rel="stylesheet" type="text/css" href="autoComplete.css" media="all"/></head><body>  <h1>郵箱自動補(bǔ)全 + 上下翻動</h1>  <p>當(dāng)在輸入框內(nèi)輸入 @ 時(shí),自動顯示各個(gè)郵箱的下拉列表。</p>  <div class="wrap">    <form action="result.php" method="post">      <input type="text" name="email" id="email" class="inp" autocomplete="off"/><br/><br/>      <input type="text" name="other" class="inp" autocomplete="off"/><br/><br/>      <input type="submit" value="提交表單" id="submit"/>    </form>  </div></body></html><script type="text/javascript" src="jquery.min.js"></script><script type="text/javascript" src="jquery.autoComplete.js"></script><script type="text/javascript">$(function(){  $.AutoComplete('#email');});</script>

css 代碼:

@charset 'utf-8';.wrap{width:200px;margin:0 auto;}h1{font-size:36px;text-align:center;line-height:60px;}p{font-size:20px;text-align:center;line-height:60px;}.inp{width:190px;border:1px solid #ccc;border-radius:5px;height:30px;line-height:30px;padding:5px;}#AutoComplete{background:#fff;border:1px solid #4190db;display:none;width:200px;}#AutoComplete ul{list-style-type:none;margin:0;padding:0;}#AutoComplete li{color:#333;cursor:pointer;font:12px/22px /5b8b/4f53;text-indent:5px;}#AutoComplete .hover{background:#6eb6fe;color:#fff;}

js 代碼:

jQuery.AutoComplete = function(selector){  var elt = $(selector);  var autoComplete,autoLi;  var strHtml = [];  strHtml.push('<div class="AutoComplete" id="AutoComplete">');  strHtml.push('  <ul class="AutoComplete_ul">');  strHtml.push('    <li class="AutoComplete_title">請選擇郵箱后綴</li>');  strHtml.push('    <li hz="@qq.com"></li>');  strHtml.push('    <li hz="@163.com"></li>');  strHtml.push('    <li hz="@126.com"></li>');  strHtml.push('    <li hz="@sohu.com"></li>');  strHtml.push('    <li hz="@sina.com"></li>');  strHtml.push('  </ul>');  strHtml.push('</div>');  $('body').append(strHtml.join(''));  autoComplete = $('#AutoComplete');  autoComplete.data('elt',elt);  autoLi = autoComplete.find('li:not(.AutoComplete_title)');  autoLi.mouseover(function(){    $(this).siblings().filter('.hover').removeClass('hover');    $(this).addClass('hover');  }).mouseout(function(){    $(this).removeClass('hover');  }).mousedown(function(){    autoComplete.data('elt').val($(this).text()).change();    autoComplete.hide();  });  //用戶名補(bǔ)全+翻動  elt.keyup(function(e){    if(/13|38|40|116/.test(e.keyCode) || this.value == ''){      return false;    }    var username = this.value;    if(username.indexOf('@') == -1){      autoComplete.hide();      return false;    }    autoLi.each(function(){      this.innerHTML = username.replace(//@+.*/,'') + $(this).attr('hz');      if(this.innerHTML.indexOf(username) >= 0){        $(this).show();      }else{        $(this).hide();      }    }).filter('.hover').removeClass('hover');    autoComplete.show().css({      left: $(this).offset().left,      top: $(this).offset().top + $(this).outerHeight(true) - 1,      position: 'absolute',      zIndex: '99999'    });    if(autoLi.filter(':visible').length == 0){      autoComplete.hide();    }else{      autoLi.filter(':visible').eq(0).addClass('hover');    }  }).keydown(function(e){    if(e.keyCode == 38){ //上      autoLi.filter('.hover').prev().not('.AutoComplete_title').addClass('hover').next().removeClass('hover');    }else if(e.keyCode == 40){ //下      autoLi.filter('.hover').next().addClass('hover').prev().removeClass('hover');    }else if(e.keyCode == 13){ //Enter      autoLi.filter('.hover').mousedown();      e.preventDefault();  //如有表單,阻止表單提交    }  }).focus(function(){    autoComplete.data('elt',$(this));  }).blur(function(){    autoComplete.hide();  });}

result.php

<?phpecho $_POST['email'] . "<br/>" . $_POST['other'];?>

完整實(shí)例代碼點(diǎn)擊此處本站下載

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)

希望本文所述對大家jQuery程序設(shè)計(jì)有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 南和县| 青川县| 德惠市| 南城县| 伊吾县| 阜阳市| 临澧县| 龙州县| 厦门市| 蒙阴县| 盐亭县| 崇信县| 双牌县| 普宁市| 凤山市| 澜沧| 茶陵县| 新竹县| 阿拉善右旗| 陵水| 青州市| 新民市| 日喀则市| 交城县| 金平| 安阳市| 慈溪市| 克拉玛依市| 孝义市| 罗田县| 布拖县| 祥云县| 监利县| 米泉市| 百色市| 金平| 潮州市| 雷州市| 霞浦县| 吴川市| 靖远县|