JS prompt text box email address completion
This time I will bring you the JS prompt text box email address completion. What are the precautions for the JS prompt text box email address completion? The following is a practical case, let’s take a look. .
What I want to achieve now is an effect similar to the email prompt box when logging in to NetEase, but I plan to change it slightly here, that is, when entering @, the email prompt list will appear
The principle of implementing prompts is to use regular matching
The code is as follows:
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>邮箱补全提示</title> <style> ul{padding:0px;margin:0px;} .login_autoComplete{width:256px;border:1px solid #4190db;position:absolute;background-color:#ffffff;z-index:99;top:109px;left:40px;display:none} .login_auto_ul em{font-style:normal} .login_auto_ul li.login_auto_title{font-weight:normal;line-height:30px;} .login_auto_ul li{line-height:22px;text-indent:5px;font-family:"Arial";cursor:pointer;font-weight:bold;color:#333} .login_auto_ul li.hover,.login_auto_ul li.curr{color:#ffffff;background-color:#6eb6fe} </style> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script> window.email_auto = function(selector){ var elt = $(selector); var strHtml = '<p class="login_autoComplete" id="login_autoComplete">'+ ' <ul class="login_auto_ul">'+ ' <li class="login_auto_title">请选择邮箱后缀</li>'+ ' <li class="hover" hz="@qq.com"></li>'+ ' <li hz="@163.com"></li>'+ ' <li hz="@126.com"></li>'+ ' <li hz="@yahoo.com"></li>'+ ' <li hz="@sina.com"></li>'+ ' <li hz="@21cn.com"></li>'+ ' </ul>'+ ' </p>'; var lc = "#login_autoComplete"; var autoComplete,autoLi; if($(lc).length==0){ $("body").append(strHtml); $(lc).data("elt",elt); autoComplete = $("#login_autoComplete"); autoLi = autoComplete.find("li:not(.login_auto_title)"); autoLi.mouseover(function(){ $(this).siblings().filter(".hover").removeClass("hover"); $(this).addClass("hover"); }).mouseout(function(){ $(this).removeClass("hover"); }).mousedown(function(){ $(lc).data("elt").val($(this).text()).change(); $(this).parent().parent().hide(); }); }else{ $(lc).data("elt",elt); autoComplete = $("#login_autoComplete"); autoLi = autoComplete.find("li:not(.login_auto_title)"); } $(lc).css("width",elt.outerWidth()-1); //用户名补全+翻动 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 }); if(autoLi.filter(":visible").length==0){ autoComplete.hide(); }else{ autoLi.filter(":visible").eq(0).addClass("hover"); } }).change(function(){ $("#login_autoComplete").hide(); }).keydown(function(e){ if(e.keyCode==38){ //上 autoLi.filter(".hover").prev().not(".login_auto_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(); } }).focus(function(){ $("#login_autoComplete").data("elt",$(this)); }); } $(function(){ email_auto("#xxx"); }); </script> </head> <body> 脚本之家测试:邮箱补全提示<br/> <input type="text" id="xxx" style="width:300px"/> </body> </html>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
$.ajax() method how to obtain json data from the server
getBoundingClientRect usage method and Compatibility handling
The above is the detailed content of JS prompt text box email address completion. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



This article provides a detailed Gate.io registration tutorial, covering every step from accessing the official website to completing registration, including filling in registration information, verifying, reading user agreements, etc. The article also emphasizes security measures after successful registration, such as setting up secondary verification and completing real-name authentication, and gives tips from beginners to help users safely start their digital asset trading journey.

This article provides newbies with detailed Gate.io registration tutorials, guiding them to gradually complete the registration process, including accessing the official website, filling in information, identity verification, etc., and emphasizes the security settings after registration. In addition, the article also mentioned other exchanges such as Binance, Ouyi and Sesame Open Door. It is recommended that novices choose the right platform according to their own needs, and remind readers that digital asset investment is risky and should invest rationally.

A detailed introduction to the login operation of the Sesame Open Exchange web version, including login steps and password recovery process. It also provides solutions to common problems such as login failure, unable to open the page, and unable to receive verification codes to help you log in to the platform smoothly.

The method of handling Laravel's email failure to send verification code is to use Laravel...

Method for obtaining the return code when Laravel email sending fails. When using Laravel to develop applications, you often encounter situations where you need to send verification codes. And in reality...

OKX Ouyi is a leading cryptocurrency trading platform. This article will provide detailed steps to guide you on how to register an OKX Ouyi official website account. You will learn how to access the official website, choose the registration method, fill in the necessary information, and complete the registration process. The article also contains information about precautions, such as the importance of using real personal information and setting a strong password.

This article provides a detailed Gate.io web version latest registration tutorial to help users easily get started with digital asset trading. The tutorial covers every step from accessing the official website to completing registration, and emphasizes security settings after registration. The article also briefly introduces other trading platforms such as Binance, Ouyi and Sesame Open Door. It is recommended that users choose the right platform according to their own needs and pay attention to investment risks.

Gateio Exchange app download channels for old versions, covering official, third-party application markets, forum communities and other channels. It also provides download precautions to help you easily obtain old versions and solve the problems of discomfort in using new versions or device compatibility.
