search
HomeWeb Front-endJS Tutorialjquery implements non-dynamic search

jquery implements non-dynamic search

Apr 19, 2018 pm 04:24 PM
jqueryaccomplishsearch

This time I will bring you jquery to implement non-dynamic search. What are the precautions for jquery to implement non-dynamic search. The following is a practical case, let's take a look.

<!DOCTYPE html>
<html>
 <head>
 <metacharset="UTF-8">
 <title>jquery实现静态搜索功能</title>
 <!-- 最新版本的 Bootstrap 核心 css 文件 -->
 <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">
 <!-- 可选的 Bootstrap 主题文件(一般不用引入) -->
 <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&#39;s JavaScript plugins) -->
 <scriptsrc="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
 <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
 <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>
 <pclass="container">
 <p> </p>
 <pclass="bs-example bs-example-tabs"data-example-id="togglable-tabs">
 <pclass="collapse navbar-collapse"id="bs-example-navbar-collapse-1">
  <ulid="myTabs"class="nav navbar-nav 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">克利夫兰 骑士</a>
  </li>
  <lirole="presentation"class="">
  <ahref="#second"rel="external nofollow"role="tab"id="second-tab"data-toggle="tab"aria-controls="second"aria-expanded="false">金州 勇士</a>
  </li>
  <lirole="presentation"class="">
  <ahref="#third"rel="external nofollow"role="tab"id="third-tab"data-toggle="tab"aria-controls="third"aria-expanded="false">波士顿 凯尔特人</a>
  </li>
  <lirole="presentation"class="">
  <ahref="#fouth"rel="external nofollow"role="tab"id="fouth-tab"data-toggle="tab"aria-controls="fouth"aria-expanded="false">休斯顿 火箭</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">搜索结果tab隐藏</a>
  </li>
  </ul>
  <formclass="navbar-form navbar-right">
  <pclass="form-group">
  <pclass="input-group">
  <pclass="input-group-btn">
   <selectclass="form-control"id="searchSelect">
   <optionvalue="all"selected="selected">全部</option>
   <optionvalue="name">姓名</option>
   <optionvalue="position">位置</option>
   <optionvalue="about">介绍</option>
   </select>
  </p>
  <inputtype="text"id="searchText"class="form-control"placeholder="搜索内容">
  </p>
  </p>
  <buttontype="button"class="btn btn-default"id="searchBth">搜索</button>
  </form>
 </p>
 <pid="myTabContent"class="tab-content">
  <prole="tabpanel"class="tab-pane fade active in"id="first"aria-labelledby="first-tab">
  <tableclass="table table-bordered table-striped">
  <thead>
  <tr>
   <th>号码</th>
   <th>姓名</th>
   <th>位置</th>
   <th>身高</th>
   <th>体重</th>
   <th>介绍</th>
  </tr>
  </thead>
  <tbody>
  <tr>
   <td>23</td>
   <td>勒布朗-詹姆斯</td>
   <td>小前锋</td>
   <td>203CM</td>
   <td>113KG</td>
   <td>四届NBA最有价值球员奖</td>
  </tr>
  <tr>
   <td>2</td>
   <td>凯尔-欧文</td>
   <td>控球后卫</td>
   <td>191CM</td>
   <td>88KG</td>
   <td>15-16赛季NBA总冠军</td>
  </tr>
  <tr>
   <td>0</td>
   <td>凯文-乐福</td>
   <td>大前锋/中锋</td>
   <td>208CM</td>
   <td>110KG</td>
   <td>15-16赛季获得NBA总冠军</td>
  </tr>
  <tr>
   <td>13</td>
   <td>特里斯坦-汤普森</td>
   <td>大前锋</td>
   <td>206CM</td>
   <td>103KG</td>
   <td>擅长拼抢进攻篮板球</td>
  </tr>
  <tr>
   <td>5</td>
   <td>J.R.史密斯</td>
   <td>得分后卫</td>
   <td>198CM</td>
   <td>102KG</td>
   <td>15-16赛季NBA总冠军</td>
  </tr>
  </tbody>
  </table>
  </p>
  <prole="tabpanel"class="tab-pane fade"id="second"aria-labelledby="second-tab">
  <tableclass="table table-bordered table-striped">
  <thead>
  <tr>
   <th>号码</th>
   <th>姓名</th>
   <th>位置</th>
   <th>身高</th>
   <th>体重</th>
   <th>介绍</th>
  </tr>
  </thead>
  <tbody>
  <tr>
   <td>30</td>
   <td>斯蒂芬-库里</td>
   <td>控球后卫</td>
   <td>191CM</td>
   <td>83.9KG</td>
   <td>两届NBA最有价值球员奖 三分精准</td>
  </tr>
  <tr>
   <td>11</td>
   <td>克莱-汤普森</td>
   <td>得分后卫</td>
   <td>201CM</td>
   <td>93KG</td>
   <td>14-15赛季NBA总冠军</td>
  </tr>
  <tr>
   <td>35</td>
   <td>凯文-杜兰特</td>
   <td>小前锋/大前锋</td>
   <td>211CM</td>
   <td>106.6KG</td>
   <td>得分手段多样投篮精准</td>
  </tr>
  <tr>
   <td>23</td>
   <td>德雷蒙德-格林</td>
   <td>前锋</td>
   <td>201CM</td>
   <td>104KG</td>
   <td>顶级锋线防守者</td>
  </tr>
  <tr>
   <td>9</td>
   <td>安德鲁-伊格达拉</td>
   <td>得分后卫</td>
   <td>198CM</td>
   <td>94KG</td>
   <td>迷你版勒布朗身体素质极佳</td>
  </tr>
  </tbody>
  </table>
  </p>
  <prole="tabpanel"class="tab-pane fade"id="third"aria-labelledby="third-tab">
  <tableclass="table table-bordered table-striped">
  <thead>
  <tr>
   <th>号码</th>
   <th>姓名</th>
   <th>位置</th>
   <th>身高</th>
   <th>体重</th>
   <th>介绍</th>
  </tr>
  </thead>
  <tbody>
  <tr>
   <td>4</td>
   <td>以赛亚-托马斯</td>
   <td>控球后卫</td>
   <td>175CM</td>
   <td>84KG</td>
   <td>球风强硬 能够突破 具备三分射程</td>
  </tr>
  <tr>
   <td>0</td>
   <td>埃弗里-布拉德利</td>
   <td>控球后卫</td>
   <td>188CM</td>
   <td>82KG</td>
   <td>15-16赛季最佳防守阵容第一阵容</td>
  </tr>
  <tr>
   <td>42</td>
   <td>艾尔-霍福德</td>
   <td>中锋</td>
   <td>208CM</td>
   <td>111KG</td>
   <td>球风全面的内线 中距离精准</td>
  </tr>
  <tr>
   <td>9</td>
   <td>贾伊-克劳德</td>
   <td>大前锋</td>
   <td>198CM</td>
   <td>107KG</td>
   <td>能量四射的双能锋</td>
  </tr>
  <tr>
   <td>36</td>
   <td>马库斯-斯玛特</td>
   <td>控球后卫</td>
   <td>193CM</td>
   <td>100KG</td>
   <td>敢于突破不惧身体对抗球风无私</td>
  </tr>
  </tbody>
  </table>
  </p>
  <prole="tabpanel"class="tab-pane fade"id="fouth"aria-labelledby="fouth-tab">
  <tableclass="table table-bordered table-striped">
  <thead>
  <tr>
   <th>号码</th>
   <th>姓名</th>
   <th>位置</th>
   <th>身高</th>
   <th>体重</th>
   <th>介绍</th>
  </tr>
  </thead>
  <tbody>
  <tr>
   <td>13</td>
   <td>詹姆斯-哈登</td>
   <td>后卫</td>
   <td>196CM</td>
   <td>99.8KG</td>
   <td>两次入选NBA最佳阵容第一阵容</td>
  </tr>
  <tr>
   <td>1</td>
   <td>特雷沃-阿里扎</td>
   <td>小前锋</td>
   <td>203CM</td>
   <td>95.3KG</td>
   <td>08-09赛季NBA总冠军</td>
  </tr>
  <tr>
   <td>2</td>
   <td>帕特里克-贝弗利</td>
   <td>控球后卫</td>
   <td>185CM</td>
   <td>84KG</td>
   <td>2015年全明星技巧挑战赛冠军</td>
  </tr>
  <tr>
   <td>10</td>
   <td>埃里克-戈登</td>
   <td>得分后卫</td>
   <td>191CM</td>
   <td>100.7KG</td>
   <td>属于攻击型得分后卫</td>
  </tr>
  <tr>
   <td>3</td>
   <td>莱恩-安德森</td>
   <td>大前锋</td>
   <td>208CM</td>
   <td>109KG</td>
   <td>投篮型内线出手快</td>
  </tr>
  </tbody>
  </table>
  </p>
  <!-- 显示搜索结果框架 -->
  <prole="searchTable"class="tab-pane fade"id="search"aria-labelledby="search-tab">
  <h3 id="搜索结果">搜索结果</h3>
  <tableclass="table table-bordered table-striped">
  <thead>
  <tr>
   <th>号码</th>
   <th>姓名</th>
   <th>位置</th>
   <th>身高</th>
   <th>体重</th>
   <th>介绍</th>
  </tr>
  </thead>
  <tbody>
  </tbody>
  </table>
  </p>
 </p>
 </p>
 <p><em>信息摘自互联网内容 若有冒犯请原谅 请留言反馈 立即删除</em></p>
 </p>
 <script>
 $(&#39;#myTabs a&#39;).click(function(e) {
 e.preventDefault()
 $(this).tab(&#39;show&#39;)
 })
 $(&#39;#searchText&#39;).change(function() {
 console.log("dd");
 var searchText = $(this).val();
 var searchSelect = $(&#39;#searchSelect&#39;).val();
 var $searchTr = "";
 if(searchText != "") {
  $(&#39;#search tbody&#39;).html("");
  //筛选搜索
  if(searchSelect == "name") {
  $searchTr = $(&#39;#myTabContent&#39;).find(&#39;td:nth-child(2):contains(&#39; + searchText + &#39;)&#39;).parent();
  } else if(searchSelect == "position") {
  $searchTr = $(&#39;#myTabContent&#39;).find(&#39;td:nth-child(3):contains(&#39; + searchText + &#39;)&#39;).parent();
  } else if(searchSelect == "about") {
  $searchTr = $(&#39;#myTabContent&#39;).find(&#39;td:nth-child(6):contains(&#39; + searchText + &#39;)&#39;).parent();
  } else {
  $searchTr = $(&#39;#myTabContent&#39;).find(&#39;td:contains(&#39; + searchText + &#39;)&#39;).parent();
  }
  $searchTr.each(function(i, e) {
  $(&#39;#search tbody&#39;).append($(e).clone(true));
  });
  //如果没有搜索结果 显示一个报错p
  if($searchTr.length <= 0) {
  $(&#39;#search tbody&#39;).html(&#39;<tdcolspan="7"><pclass="alert alert-warning"role="alert">没有内容</p></td>&#39;)
  }
  $(&#39;#search-tab&#39;).tab(&#39;show&#39;);
 }
 }).keyup(function() {
 $(this).change();
 })
 $(&#39;#searchBth&#39;).click(function() {
 $(&#39;#searchText&#39;).change();
 })
 </script>
 </body>
</html>

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

jQuery implements single-line announcement carousel

Detailed explanation of the use of jquery plug-in extension

base64 implements encryption and decryption functions

The above is the detailed content of jquery implements non-dynamic search. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Future of Python and JavaScript: Trends and PredictionsThe Future of Python and JavaScript: Trends and PredictionsApr 27, 2025 am 12:21 AM

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Python vs. JavaScript: Development Environments and ToolsPython vs. JavaScript: Development Environments and ToolsApr 26, 2025 am 12:09 AM

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Is JavaScript Written in C? Examining the EvidenceIs JavaScript Written in C? Examining the EvidenceApr 25, 2025 am 12:15 AM

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript's Role: Making the Web Interactive and DynamicJavaScript's Role: Making the Web Interactive and DynamicApr 24, 2025 am 12:12 AM

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C   and JavaScript: The Connection ExplainedC and JavaScript: The Connection ExplainedApr 23, 2025 am 12:07 AM

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

The Role of C/C   in JavaScript Interpreters and CompilersThe Role of C/C in JavaScript Interpreters and CompilersApr 20, 2025 am 12:01 AM

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.