Jquery implements the static search function (you can enter search text)

Source: Internet
Author: User

Jquery implements the static search function (you can enter search text)

The Code is as follows:

<! DOCTYPE html>

<Html>

<Head>

<Metacharset = "UTF-8">

<Title> jquery implements the static search function </title>

<! -- The latest Bootstrap core css file -->

<Linkrel = "stylesheet" href = "https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel = "external nofollow" integrity = "sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va + PmSTsz/K68vbdEjh4u" crossorigin = "anonymous">

<! -- Optional Bootstrap topic file (not introduced in general) -->

<Linkrel = "stylesheet" href = "https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel = "external nofollow" integrity = "sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin = "anonymous">

<! -- JQuery (necessary for Bootstrap's JavaScript plugins) -->

<Scriptsrc = "https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"> </script>

<! -- The latest Bootstrap core JavaScript file -->

<Scriptsrc = "https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity = "sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin = "anonymous"> </script>

<Style>

. Navbar-collapse {

Padding: 0;

}

. Alert {

Margin: 20px;

}

. Input-group select. form-control: last-child {

Border-top-left-radius: 4px;

Border-bottom-left-radius: 4px;

Margin-right:-1px;

}

. Tab-content {

Padding-top: 20px;

}

</Style>

</Head>

<Body>

<Divclass = "container">

<P> </p>

<Divclass = "bs-example-tabs" data-example-id = "togglable-tabs">

<Divclass = "collapse navbar-collapse" id = "bs-example-navbar-collapse-1">

<Ulid = "myTabs" class = "nav navbar-nav-pills" role = "tablist">

<Lirole = "presentation" class = "active">

<Ahref = "# first" rel = "external nofollow" role = "tab" id = "first-tab" data-toggle = "tab" aria-controls = "first" aria -expanded = "true"> Cleveland server guard </a>

</Li>

<Lirole = "presentation" class = "">

<Ahref = "# second" rel = "external nofollow" role = "tab" id = "second-tab" data-toggle = "tab" aria-controls = "second" aria -expanded = "false"> Golden State Warriors </a>

</Li>

<Lirole = "presentation" class = "">

<Ahref = "# third" rel = "external nofollow" role = "tab" id = "third-tab" data-toggle = "tab" aria-controls = "third" aria -expanded = "false"> Boston Celtics </a>

</Li>

<Lirole = "presentation" class = "">

<Ahref = "# fouth" rel = "external nofollow" role = "tab" id = "fouth-tab" data-toggle = "tab" aria-controls = "fouth" aria -expanded = "false"> Houston Rocket </a>

</Li>

<Lirole = "presentation" class = "hidden">

<Ahref = "# search" rel = "external nofollow" role = "tab" id = "search-tab" data-toggle = "tab" aria-controls = "search" aria -expanded = "false"> Search Result tab hiding </a>

</Li>

</Ul>

<Formclass = "navbar-form navbar-right">

<Divclass = "form-group">

<Divclass = "input-group">

<Divclass = "input-group-btn">

<Selectclass = "form-control" id = "searchSelect">

<Optionvalue = "all" selected = "selected"> all </option>

<Optionvalue = "name"> name </option>

<Optionvalue = "position"> position </option>

<Optionvalue = "about"> introduction </option>

</Select>

</Div>

<Inputtype = "text" id = "searchText" class = "form-control" placeholder = "search content">

</Div>

</Div>

<Buttontype = "button" class = "btn-default" id = "searchBth"> Search </button>

</Form>

</Div>

<Divid = "myTabContent" class = "tab-content">

<Divrole = "tabpanel" class = "tab-pane fade active in" id = "first" aria-labelledby = "first-tab">

<Tableclass = "table-bordered table-striped">

<Thead>

<Tr>

<Th> Number </th>

<Th> name </th>

<Th> location </th>

<Th> height </th>

<Th> weight </th>

<Th> introduction </th>

</Tr>

</Thead>

<Tbody>

<Tr>

<Td> 23 </td>

<Td> LeBron James </td>

<Td> small forward </td>

<Td> 203 </td>

<Td> 113 </td>

<Td> fourth NBA Most Valuable Player award </td>

</Tr>

<Tr>

<Td> 2 </td>

<Td> Kyle Owen </td>

<Td> ball guard </td>

<Td> 191 </td>

<Td> 88 KG </td>

<Td> NBA championship in the 15-16 season </td>

</Tr>

<Tr>

<Td> 0 </td>

<Td> Kevin-NLP </td>

<Td> power forward/center </td>

<Td> 208 </td>

<Td> 110 </td>

<Td> won the NBA championship in the 15-16 season </td>

</Tr>

<Tr>

<Td> 13 </td>

<Td> Terry Thompson </td>

<Td> power forward </td>

<Td> 206 </td>

<Td> 103 </td>

<Td> be good at attacking the rebound </td>

</Tr>

<Tr>

<Td> 5 </td>

<Td> J. R. Smith </td>

<Td> score guard </td>

<Td> 198 </td>

<Td> 102 </td>

<Td> NBA championship in the 15-16 season </td>

</Tr>

</Tbody>

</Table>

</Div>

<Divrole = "tabpanel" class = "tab-pane fade" id = "second" aria-labelledby = "second-tab">

<Tableclass = "table-bordered table-striped">

<Thead>

<Tr>

<Th> Number </th>

<Th> name </th>

<Th> location </th>

<Th> height </th>

<Th> weight </th>

<Th> introduction </th>

</Tr>

</Thead>

<Tbody>

<Tr>

<Td> 30 </td>

<Td> Stephen Curry </td>

<Td> ball guard </td>

<Td> 191 </td>

<Td> 83.9 </td>

<Td> three-point precision of the two NBA Most Valuable Player Awards </td>

</Tr>

<Tr>

<Td> 11 </td>

<Td> Clay Thompson </td>

<Td> score guard </td>

<Td> 201 </td>

<Td> 93 KG </td>

<Td> NBA championship in the 14-15 season </td>

</Tr>

<Tr>

<Td> 35 </td>

<Td> Kevin Durant </td>

<Td> small forward/large forward </td>

<Td> 211 </td>

<Td> 106.6 </td>

<Td> diverse scoring techniques and precise shooting </td>

</Tr>

<Tr>

<Td> 23 </td>

<Td> D Raymond-green </td>

<Td> forward </td>

<Td> 201 </td>

<Td> 104 </td>

<Td> top-level Front Line Defender </td>

</Tr>

<Tr>

<Td> 9 </td>

<Td> Andrew igdala </td>

<Td> score guard </td>

<Td> 198 </td>

<Td> 94 KG </td>

<Td> excellent physical fitness for the mini version of LeBron </td>

</Tr>

</Tbody>

</Table>

</Div>

<Divrole = "tabpanel" class = "tab-pane fade" id = "third" aria-labelledby = "third-tab">

<Tableclass = "table-bordered table-striped">

<Thead>

<Tr>

<Th> Number </th>

<Th> name </th>

<Th> location </th>

<Th> height </th>

<Th> weight </th>

<Th> introduction </th>

</Tr>

</Thead>

<Tbody>

<Tr>

<Td> 4 </td>

<Td> Isa-Thomas </td>

<Td> ball guard </td>

<Td> 175 </td>

<Td> 84 KG </td>

<Td> the ball is tough and can break beyond the three-point range </td>

</Tr>

<Tr>

<Td> 0 </td>

<Td> evri-Bradley </td>

<Td> ball guard </td>

<Td> 188 </td>

<Td> 82 KG </td>

<Td> top lineup of the best defensive lineup in the 15-16 season </td>

</Tr>

<Tr>

<Td> 42 </td>

<Td> Al-Horford </td>

<Td> center </td>

<Td> 208 </td>

<Td> 111 </td>

<Td> comprehensive internal distance and accuracy </td>

</Tr>

<Tr>

<Td> 9 </td>

<Td> Jai-Claude </td>

<Td> power forward </td>

<Td> 198 </td>

<Td> 107 </td>

<Td> energetic dual-energy front </td>

</Tr>

<Tr>

<Td> 36 </td>

<Td> Marcus-smart </td>

<Td> ball guard </td>

<Td> 193 </td>

<Td> 100 </td>

<Td> dare to break through without fear of physical confrontation and selflessness </td>

</Tr>

</Tbody>

</Table>

</Div>

<Divrole = "tabpanel" class = "tab-pane fade" id = "fouth" aria-labelledby = "fouth-tab">

<Tableclass = "table-bordered table-striped">

<Thead>

<Tr>

<Th> Number </th>

<Th> name </th>

<Th> location </th>

<Th> height </th>

<Th> weight </th>

<Th> introduction </th>

</Tr>

</Thead>

<Tbody>

<Tr>

<Td> 13 </td>

<Td> James harden </td>

<Td> defender </td>

<Td> 196 </td>

<Td> 99.8 </td>

<Td> two times in the NBA's top lineup </td>

</Tr>

<Tr>

<Td> 1 </td>

<Td> trevo-aliza </td>

<Td> small forward </td>

<Td> 203 </td>

<Td> 95.3 </td>

<Td> NBA championship in the 08-09 season </td>

</Tr>

<Tr>

<Td> 2 </td>

<Td> Patrick Beverly </td>

<Td> ball guard </td>

<Td> 185 </td>

<Td> 84 KG </td>

<Td> champion of the 2015 all-star skill challenge </td>

</Tr>

<Tr>

<Td> 10 </td>

<Td> Eric Gordon </td>

<Td> score guard </td>

<Td> 191 </td>

<Td> 100.7 </td>

<Td> belongs to the attacking scoring defender </td>

</Tr>

<Tr>

<Td> 3 </td>

<Td> Ryan Anderson </td>

<Td> power forward </td>

<Td> 208 </td>

<Td> 109 </td>

<Td> fast shot in the shooting Model </td>

</Tr>

</Tbody>

</Table>

</Div>

<! -- Display Search Result Framework -->

<Divrole = "searchTable" class = "tab-pane fade" id = "search" aria-labelledby = "search-tab">

<H3> Search Result

<Tableclass = "table-bordered table-striped">

<Thead>

<Tr>

<Th> Number </th>

<Th> name </th>

<Th> location </th>

<Th> height </th>

<Th> weight </th>

<Th> introduction </th>

</Tr>

</Thead>

<Tbody>

</Tbody>

</Table>

</Div>

</Div>

</Div>

<P> <em> the information is excerpted from Internet content. If any, please forgive me and leave a message. </em> </p>

</Div>

<Script>

$ ('# MyTabs A'). click (function (e ){

E. preventDefault ()

$ (This). tab ('show ')

})

$ ('# Searchtext'). change (function (){

Console. log ("dd ");

Var searchText = $ (this). val ();

Var searchSelect = $ ('# searchselect'). val ();

Var $ searchTr = "";

If (searchText! = ""){

$ ('# Search tbody'{.html ("");

// Filter and search

If (searchSelect = "name "){

$ SearchTr = $ ('# mytabcontent'). find ('td: nth-child (2): contains (' + searchText + '). parent ();

} Else if (searchSelect = "position "){

$ SearchTr = $ ('# mytabcontent'). find ('td: nth-child (3): contains (' + searchText + '). parent ();

} Else if (searchSelect = "about "){

$ SearchTr = $ ('# mytabcontent'). find ('td: nth-child (6): contains (' + searchText + '). parent ();

} Else {

$ SearchTr = $ ('# mytabcontent'). find ('td: contains (' + searchText + '). parent ();

}

$ SearchTr. each (function (I, e ){

$ ('# Search tbody'). append ($ (e). clone (true ));

});

// If no search results show an error div

If ($ searchTr. length <= 0 ){

$ ('# Search tbody'0000.html (' <tdcolspan = "7"> <divclass = "alert-warning" role = "alert"> NO content </div> </td> ')

}

$ ('# Search-tab'). tab ('show ');

}

}). Keyup (function (){

$ (This). change ();

})

$ ('# SearchBth'). click (function (){

$ ('# Searchtext'). change ();

})

</Script>

</Body>

</Html>


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.