AJAX Smart Hint +textbox dynamic build dropdown box

Source: Internet
Author: User
<div class= "searchwellist" > Quick query: <select id= "Searchselect" runat= "Server" ><option value= "1" selected= "Selected" > by inner tube code </option><option value= "2" > by tag Code </option></select></div>
             <div class= "Searchwel" id= "Search_div" ><input "text" type= "id=" "fastsearchtxt" input the individual code or the inner tube code "value=". NameList "   onfocus=" if (value== ' input individual encoding or inner tube encoding ') {value= '} ' onblur= ' if (value== ') {value= ' input individual encoding or inner tube encoding '} '/>< /div>

Here is the referenced JS file

$ (document). Ready (function () {$ ("#fastsearchTxt"). KeyUp (function () {//ajax Get database query data var = $ ("#fast
        Searchtxt "). Val ();
        var num = $ ("#searchSelect option:selected"). Val ();
            $.ajax ({type: "POST", url: "ajaxsearch.aspx", Data: ' Data= ' +data+ ' &num= ' +num,
            Success:function (Message) {$ (' #fastsearchTxt '). Bedropdownlist (message);
    }
        });
});


}); (function ($) {$.fn.bedropdownlist = function (data) {//default value var defaults = {data: [' not
        Hing ']};
        var options = {Data:data}; options = $.extend (defaults, options);
            Make parameter override var bindevent = function (o) {var tmpid = "Tmpselector_" + $ (o). attr ("id");//Generate temporary ID
                if ($ ("#" + tmpid). Length > 0) {$ ("#" + tmpid). Remove (); Return Quit, do not go on} var datas = Options.data.split (', '); //data source//This style is set to absolute var html = "<div id=" "+ tmpid +" ' style= ' border:1px solid grey;m Ax-height:150px;position:absolute;text-align:left; overflow:auto;background:white;width:153px; '
            ><ul class= ' ui-menu ' > '; Dynamically generate a div containing Li element for (Var item in datas) {html + + <li> "+ Datas[item] +" </li>
            ";
            HTML = = "</ul></div>";
            var left = $ (o). Offset (). Left;

            var top = $ (o). Offset (). Top + $ (o). Height () + 4; The var finalize = function () {$ ("#" + tmpid + "Li"). Unbind (' click ');//Cancel Event binding $ ("#" + tmpid
            ). Remove ();
            };
            Sets the width, position, and so on of the div.
            $ ("#" + tmpid). Width ($ (o). Width () + 100);               
            $ ("#" + tmpid). Offset ({top:top, left:left});
            $ ("#" + tmpid). Remove ();
            
            $ ("#search_div"). Append (HTML); $ ("#" + tmpid). MoUseleave (function () {finalize ();});
                $ ("#" + tmpid+ "Li"). Click (function () {$ (O). Val ($ (this). text ());
                Finalize ();
                if (fn!= undefined) {fn ();//Call the function passed in.
        }
            });
            };
                    This.each (function () {//Because the selectors of jquery may match multiple objects, you need each to operate on each matching element. if ($ (this). Is (": text") = = True) {//$ (this). KeyUp (function () {Bindev ENT ($ (this));
                    Set the content to do//});

    }
                });
}; }) (JQuery);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.