Home JS special effects jQuery effects jQuery text box input text automatic filtering effect

jQuery text box input text automatic filtering effect

jQuery text box input text automatic filtering effect

jQuery text box input text automatically filter code

js code

<script type="text/javascript">
var personArr = [
    { name: 'Wanggang', src: 'img/3.png', des: 'Bad cervical vertebra', sex: 'm' },
{ name: 'Zhang San', src: 'img/4.png', des: 'Description information 2', sex: 'm' },
{ name: '李思', src: 'img/5.png', des: 'Description information 3', sex: 'm' },
{ name: 'Wang Mazi', src: 'img/1.png', des: 'Description information 4', sex: 'm' },
{ name: 'Ahai', src: 'img/2.png', des: 'Description information 5', sex: 'm' },
    { name: 'Liu Ying', src: 'img/5.png', des: 'Who am I', sex: 'f' },
    { name: 'Wang Xiuying', src: 'img/4.png', des: 'I'm very good-looking', sex: 'f' },
    { name: 'Liu Jinlei', src: 'img/1.png', des: 'You have never seen a strange face', sex: 'm' },
    { name: 'Liu Feixiang', src: 'img/2.png', des: 'Guapi Liu', sex: 'm' }
];
//Rendering function
function renderList(arr) {
    var str = "";
    arr.forEach(function (ele, index) {
        str += '<li>\
                   <img src = '+ ele.src + ' alt = "" >\
                   <p class="username">'+ ele.name + '</p>\
                   <p class="des">'+ ele.des + '</p>\
               </li > '
    })
    $("ul").html(str)
}
renderList(personArr)
//Render based on name
var searchVal = "";
var sexVal = "a";
$(".search-box").on("input", function () {
    searchVal = $(this).val();
    all()
})
//Render based on gender
$("span").on("click", function () {
    $("span").removeClass("active");
    $(this).addClass("active");
    sexVal = $(this).attr("sex");
    all()
})
//Filter the array by name
function nameFilter(name, arr) {
    return arr.filter(function (ele, index) {
        return ele.name.indexOf(name) != -1 ? true : false
    })
}
//Filter the array based on gender
function sexFilter(sex, arr) {
    if (sex == "a") {
        return arr;
    }
    return arr.filter(function (ele, index) {
        return ele.sex == sex;
    })
}
//Merge filter
function all() {
    var lastArr = nameFilter(searchVal, personArr);
    lastArr = sexFilter(sexVal, lastArr)
    renderList(lastArr)
}

</script>

A very simple jQuery text box input text automatic filtering code, query box text filtering list display code with pictures.

Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

Image and text automatic carousel effect plug-in implemented by JQuery Image and text automatic carousel effect plug-in implemented by JQuery

28 Jun 2018

This article mainly introduces the automatic image and text carousel effect plug-in implemented by JQuery, involving jQuery's method of processing mouse events and animation effects. Friends who need it can refer to it.

jQuery realizes the automatic completion effect of text box email input_jquery jQuery realizes the automatic completion effect of text box email input_jquery

16 May 2016

This article mainly introduces jQuery to realize the automatic completion effect of text box email input. You do not need to enter all the email information. Interested friends can refer to it.

jQuery method to achieve text box input synchronization_jquery jQuery method to achieve text box input synchronization_jquery

16 May 2016

This article mainly introduces jQuery's method of realizing text box input synchronization, involving related skills of jQuery element attribute operation. Friends in need can refer to the following

jquery implements Weibo text input box and displays the number of words entered during input. Effect implementation_jquery jquery implements Weibo text input box and displays the number of words entered during input. Effect implementation_jquery

16 May 2016

This article introduces the use of jquery to implement the Weibo text input box to display the number of words entered during input. Friends in need can refer to it.

jquery plug-in text intermittent automatic scrolling up effect code_jquery jquery plug-in text intermittent automatic scrolling up effect code_jquery

16 May 2016

This article mainly introduces the intermittent text automatic upward scrolling effect code of the jquery plug-in, and involves the related techniques of jquery triggering the page element transformation based on the time function to achieve the scrolling effect. Friends in need can refer to the following

Js implements text box effect with automatic prompts Js implements text box effect with automatic prompts

25 Jul 2016

Js implements text box effect with automatic prompts

Simple text box input automatic prompt_html/css_WEB-ITnose Simple text box input automatic prompt_html/css_WEB-ITnose

24 Jun 2016

Simple text box input auto-suggestion

Use jquery to manipulate the text content of the input box Use jquery to manipulate the text content of the input box

15 Mar 2018

This time I will bring you how to use jquery to operate the text content of the input box. What are the precautions for using jquery to operate the text content of the input box? The following is a practical case, let's take a look.

 
代码如下:
Event application in jquery text box takes input email as an example_jquery

16 May 2016

This article mainly introduces the event application in jquery text box, taking inputting email as an example. Friends who need it can refer to it below.

See all articles See all articles

Hot Tools

jQuery2019 Valentine's Day Confession Fireworks Animation Special Effects

jQuery2019 Valentine's Day Confession Fireworks Animation Special Effects

A very popular jQuery Valentine's Day confession fireworks animation special effect on Douyin, suitable for programmers and technical geeks to express their love to the girl they love. No matter you choose to be willing or not, you have to agree in the end.

layui responsive animated login interface template

layui responsive animated login interface template

layui responsive animated login interface template

520 Valentine's Day confession web animation special effects

520 Valentine's Day confession web animation special effects

jQuery Valentine's Day Confession Animation, 520 Confession Background Animation

Cool system login page

Cool system login page

Cool system login page

HTML5 tape music player-CASSETTE PLAYER

HTML5 tape music player-CASSETTE PLAYER

HTML5 tape music player-CASSETTE PLAYER