Use jQuery to implement a drop-down box for text input and search _ jquery-js tutorial

Source: Internet
Author: User
JQuery automatically displays the following drop-down list when you click the drop-down box input box. It is added based on the search entered in the input box, automatically searches in the background, and then uploads it to the foreground to display the page first.


Function:When you click the drop-down box, the drop-down list below is automatically displayed, and is added based on the search entered in the input box. It is automatically searched in the background and uploaded to the foreground to display the page.
Js used:

The Code is as follows:


Var $ xialaSELECT;
$ (Document). ready (function (){
InitXialaSelect ();
InitSearch ();
});
Var temptimeout = null;
Var query = "";
Function searchDev (key ){
// If (key = "") return;
Query = key;
ClearTimeout (temptimeout );
Temptimeout = setTimeout (findUnSaved, 500 );
}
Function findUnSaved ()
{
// Alert ("dd ");
// If (1 = 1) return;
$. Ajax ({
Type: "post ",
Data: {'query': query },
Url: path + "/tList. action ",
Success: function (data ){
Xiala (data );
},
Error: function (data ){
Alert ("loading failed. Please try again! ");
}
});
}
Function initSearch ()
{
// Define a drop-down button layer, configure the style (Position, positioning point coordinate, size, background image, Z axis), and append it to the end of the text box
$ XialaDIV = $ ('

'Salary .css ('position', 'absolute'salary .css ('left', $ ('# province '). position (). left + $ ('# province '). width ()-15 + 'px'0000.css ('top ',
$ ('# Province '). position (). top + 4 + 'px'background .css ('background ', 'transparent url (.. /images/lala.gif) no-repeat top left'detail .css ('height', '16px'detail .css ('width ',
'15px'0000.css ('z-Index', '20140901 ');
$ ('# Province'). after ($ xialaDIV );
// Move the mouse to modify the background image position
$ XialaDIV. mouseover (function (){
Using xialadiv.css ('background-position', '2017-16px ');
});
// Move the mouse out to modify the background image position
$ XialaDIV. mouseout (function (){
Using xialadiv.css ('background-position', '2017-0px ');
});
// Press the mouse to modify the background image position
$ XialaDIV. mousedown (function (){
Using xialadiv.css ('background-position', '2017-32px ');
});
// Release the mouse to modify the background image position
$ XialaDIV. mouseup (function (){
Using xialadiv.css ('background-position', '2017-16px ');
If ($ xialaSELECT)
$ XialaSELECT. show ();
});
$ ('# Province'). mouseup (function (){
Using xialadiv.css ('background-position', '2017-16px ');
$ XialaSELECT. show ();
});
}
Var firstTimeYes = 1;
// Text box drop-down box p
Function xiala (data ){
// First time
If ($ xialaSELECT)
{
$ XialaSELECT. empty ();
}
// Define a drop-down BOX layer, configure the style (Position, positioning point coordinate, width, and Z axis), and hide it first
// Define five option layers, configure the style (width, Z axis must be higher than the drop-down box), add the name and value attributes, and add the drop-down box Layer
$ XialaSELECT. append (data );
If (firstTimeYes = 1)
{
FirstTimeYes = firstTimeYes + 1;
} Else {
$ XialaSELECT. show ();
}
}
Function initXialaSelect ()
{
$ XialaSELECT = $ ('

'Salary .css ('position', fill ('border', '1px solid limit 809db9'salary .css('border-top', 'one'salary .css ('left', '125px'salary .css
('Top', $ ('# province '). position (). top + $ ('# province '). height () + 6 + 'px'0000.css ('width', $ ('# province '). width () + 'px'0000.css ('z-Index', percentile ('max-height', '600px ');
$ ('# Province'). after ($ xialaSELECT );
// Move the mouse at the option layer to the remove Style
$ XialaSELECT. mouseover (function (event ){
If (((event.tar get). attr ('name') = 'option '){
// When moving in, the background color becomes deeper and the word color becomes white
Watermark (event.target).css ('background-color', 'background 000077').css ('color', 'white ');
Vertex (event.tar get). mouseout (function (){
// If the color is removed, the background color turns white and the font color turns black.
Watermark (event.target).css ('background-color', '{ffff'}.css ('color', '#000000 ');
});
}
});
// Click the position to determine the pop-up display
$ XialaSELECT. mouseup (function (event ){
// If it is a drop-down button layer or a drop-down BOX layer, the drop-down BOX layer is still displayed
If (event.tar get = $ xialaSELECT. get (0) | event.tar get = $ xialaDIV. get (0 )){
$ XialaSELECT. show ();
}
Else {
// If it is an option layer, the value of the text box is changed.
If (((event.tar get). attr ('name') = 'option '){
// Pop-up value observation
Certificate ('{nce'}.val(%(event.target}.html ());
Certificate ('{d'{.val({(event.tar get). attr ("d "));
// If seleced host then hidden the dev type
If(detail (event.tar get). attr ("ass") = 3305)
{
$ ("# Ype"). hide ();
$ ("# Ost"). val (1 );
} Else {
$ ("# Ype"). show ();
$ ("# Ost"). val (-1 );
}
}
// If it is another location, the drop-down box Layer
If ($xialaSELECT.css ('display') = 'block '){
$ XialaSELECT. hide ();
}
}
});
$ XialaSELECT. hide ();
}
Var k = 1;
Document. onclick = clicks;
Function clicks ()
{
If (k = 2 ){
K = 1;
If ($ xialaSELECT)
{
If ($xialaSELECT.css ('display') = 'block '){
$ XialaSELECT. hide ();
}
}
} Else {
K = 2;
}
}


The Code is as follows:


. CBA {
Width: 150px;
Height: 18px;
}
. Selectlala {
Text-align: left;
Line-height: 20px;
Padding-left: 5px;
Width: 147px;
Font-family: Arial, verdana, tahoma;
Height: 20px;
}

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.