Simple text box input automatic prompts - when typing, you can directly asynchronously load matching items in the database and then display them.
No database is used here, and arrays are used directly to simulate data storage in PHP.
> Monitor the status of the input box, and when there is a change, immediately send data through ajax and obtain the return value.
Mainly using jQuery encapsulation is very convenient, but it seems that my compatibility is not good... Mainly provide an idea~
js part:
Bring the html part with you so you don’t know which is which
<script type="text/javascript" src="./js/jquery.min.js"></script><script type="text/javascript">$(function(){ $(":button").click(function() { /* Act on the event */ if($(":input").val() != ""){ alert("your name is " + $(":input").val()); } }); $(":input").bind("keyup",function(){ $(".info").empty(); if($(this).val() == "") return; // alert($("#name").val()); $.ajax({ type: 'get', url: 'Automatic_prompt_info.php', data: {name: $("#name").val()}, success: function(data){ // alert(data); var array = new Array(); array = data.split(","); $(".info").append($("<ul></ul>")); for(var i=0;i<array.length-1;i++){ $(".info ul").append($("<li>"+array[i]+"</li>")); } $(".info ul").on("click",function(event){ //事件委托 $("#name").val($(event.target).text()); $(".info").empty(); }) } }); });});</script>
php data part:
<style type="text/css"> html,body,div,form,input,legend,label,button,ul,li{margin: 0;padding: 0;} form,fieldset{border: 0;} .wrap{position:relative;margin: 100px auto; width: 700px; height: 400px;overflow: hidden;} input{width: 300px; height: 36px; border: 3px solid green;border-radius: 3px;font-weight: bold;} button{width: 120px; height: 42px; border: 0;padding: 8px;margin-left:-10px;background-color: green;font-weight: bold;font-size:16px;color: white;cursor: pointer;border-radius: 30px;} .info{position: relative;top: -10px;left: 14px;width: 305px;} ul{list-style: none;} li{padding: 3px 10px; border-bottom: 1px dotted #333;background-color: #ddd; } li:hover{cursor: pointer;background-color: green;} </style></head><body> <div class="wrap"> <h3 id="文本框文本自动提示-如输入fish-jack">文本框文本自动提示(如输入fish jack )</h3> <form name="form" method="get" action=""> <fieldset> <label for="search"></label> <input type="text" name="name" id="name" placeholder="Input your name"> <button type="button" id="button">search</button> </fieldset> </form> <div class="info"> </div> </div>Use simple regular matching.
<?php$names = array('adan','acos','acoss','apple','fish','fisher','fishers','jack','july','boy','boyee','girl','json'); // names$name = $_GET['name']; // name from input label$str = "";$counts = count($names);for($i = 0;$i<$counts;$i++){ if(preg_match("/^$name/", $names[$i])){ //find $str .= $names[$i]; if($i != $counts - 1) $str .= ","; }}//$data = array("A"=>$str)//echo json_encode($data); // send back infoecho $str;?>

The usage methods of HTML tags and attributes include: 1. Basic usage: Use tags such as and, and add necessary information through attributes such as src and href. 2. Advanced usage: Use data-* custom attributes to achieve complex interactions. 3. Avoid common mistakes: Make sure the property values are surrounded by quotes. 4. Performance optimization: Keep it simple, use standard attributes and CSS class names to ensure that the image has alt attributes. Mastering these will improve web development skills.

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
