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;?>

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful 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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software