Web Front-end
JS Tutorial
jQuery implements fuzzy matching query of HTML page text box (with code)
jQuery implements fuzzy matching query of HTML page text box (with code)
This time I will bring you jQuery to implement fuzzy matching query of HTML page text box (with code), jQuery to implement fuzzy matching query of HTML page text box What are the precautions , the following is a practical case, one Get up and take a look.
This function needs to be used in the project. I have used Combobox in EasyUI and searched for corresponding solutions online. However, they are not suitable for my project because I still like relatively pure things. I wrote one myself. It is relatively simple, but still usable. I have already used it in my project. I made a small demo for record. If necessary, just copy the code and modify it.
Next is the code, pure html css jquery:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<title>jQuery模糊匹配查询</title>
<style type="text/css">
#p_main {
margin: 0 auto;
width: 300px;
height: 400px;
border: 1px solid black;
margin-top: 50px;
}
#p_txt {
position: relative;
width: 200px;
margin: 0 auto;
margin-top: 40px;
}
#txt1 {
width: 99%;
}
#p_items {
position: relative;
width: 100%;
height: 200px;
border: 1px solid #66afe9;
border-top: 0px;
overflow: auto;
display: none;
}
.p_item {
width: 100%;
height: 20px;
margin-top: 1px;
font-size: 13px;
line-height: 20px;
}
</style>
</head>
<body>
<p id="p_main">
<!--表单的autocomplete="off"属性设置可以阻止浏览器默认的提示框-->
<form autocomplete="off">
<p id="p_txt">
<!--要模糊匹配的文本框-->
<input type="text" id="txt1" />
<!--模糊匹配窗口-->
<p id="p_items">
<p class="p_item">周杰伦</p>
<p class="p_item">周杰</p>
<p class="p_item">林俊杰</p>
<p class="p_item">林宥嘉</p>
<p class="p_item">林妙可</p>
<p class="p_item">唐嫣</p>
<p class="p_item">唐家三少</p>
<p class="p_item">唐朝盛世</p>
<p class="p_item">奥迪A4L</p>
<p class="p_item">奥迪A6L</p>
<p class="p_item">奥迪A8L</p>
<p class="p_item">奥迪R8</p>
<p class="p_item">宝马GT</p>
</p>
</p>
</form>
</p>
</body>
</html>
<script type="text/javascript">
//弹出列表框
$("#txt1").click(function () {
$("#p_items").css('display', 'block');
return false;
});
//隐藏列表框
$("body").click(function () {
$("#p_items").css('display', 'none');
});
//移入移出效果
$(".p_item").hover(function () {
$(this).css('background-color', '#1C86EE').css('color', 'white');
}, function () {
$(this).css('background-color', 'white').css('color', 'black');
});
//文本框输入
$("#txt1").keyup(function () {
$("#p_items").css('display', 'block');//只要输入就显示列表框
if ($("#txt1").val().length <= 0) {
$(".p_item").css('display', 'block');//如果什么都没填,跳出,保持全部显示状态
return;
}
$(".p_item").css('display', 'none');//如果填了,先将所有的选项隐藏
for (var i = 0; i < $(".p_item").length; i++) {
//模糊匹配,将所有匹配项显示
if ($(".p_item").eq(i).text().substr(0, $("#txt1").val().length) == $("#txt1").val()) {
$(".p_item").eq(i).css('display', 'block');
}
}
});
//项点击
$(".p_item").click(function () {
$("#txt1").val($(this).text());
});
</script>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 implementation of fuzzy query practical case analysis
How to deal with async/await wasteful performance issues
The above is the detailed content of jQuery implements fuzzy matching query of HTML page text box (with code). For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undress AI Tool
Undress images for free
Clothoff.io
AI clothes remover
AI Hentai Generator
Generate AI Hentai for free.
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
1378
52
Table Border in HTML
Sep 04, 2024 pm 04:49 PM
Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.
HTML margin-left
Sep 04, 2024 pm 04:48 PM
Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.
Nested Table in HTML
Sep 04, 2024 pm 04:49 PM
This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.
HTML Table Layout
Sep 04, 2024 pm 04:54 PM
Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.
HTML Input Placeholder
Sep 04, 2024 pm 04:54 PM
Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.
HTML Ordered List
Sep 04, 2024 pm 04:43 PM
Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively
Moving Text in HTML
Sep 04, 2024 pm 04:45 PM
Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.
HTML onclick Button
Sep 04, 2024 pm 04:49 PM
Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.


