ホームページ  >  記事  >  ウェブフロントエンド  >  簡易テキストボックス自動入力プロンプト_html/css_WEB-ITnose

簡易テキストボックス自動入力プロンプト_html/css_WEB-ITnose

WBOY
WBOYオリジナル
2016-06-24 11:48:13915ブラウズ

シンプルなテキスト ボックス入力の自動プロンプト - 入力時に、データベース内の一致する項目を非同期で直接ロードして表示できます。

ここではデータベースは使用されず、データ ストレージは PHP の配列を使用して直接シミュレートされます。

デモ デモンストレーション

原理は主に次のとおりです。

変更があった場合、データは AJAX を介して送信され、を取得しました戻り値。

主にjQueryのパッケージングを使うのはとても便利ですが、私の相性が悪いようです...主にアイデアを提供します〜

js部分:

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

ちなみに、html部分を持ってきて、どれがどれだか分からないように

    <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>文本框文本自动提示(如输入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>

php データ部分:

単純な通常のマッチングを使用するだけです。 ❤️
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。