jQuery-App輸入框?qū)崿F(xiàn)實(shí)時(shí)搜索
本文實(shí)例為大家分享了jQuery-App輸入框?qū)崿F(xiàn)實(shí)時(shí)搜索的具體代碼,供大家參考,具體內(nèi)容如下
1、實(shí)現(xiàn)實(shí)時(shí)搜索
其實(shí)原理就是很簡單,實(shí)時(shí)獲取輸入框的值即可,并且對(duì)不同情況操作進(jìn)行不同處理。
2、這里只貼出主要事件語句代碼,具體一些操作要視具體情況而定
// 監(jiān)聽搜索框的內(nèi)容變化 實(shí)現(xiàn)實(shí)時(shí)搜索 $(".searchContent").bind("input propertychange change", function () { studentName = $(".searchContent").val(); var searchContent = $(".searchContent").val(); if (searchContent.length > 0) { $(".clearSearchContent").removeClass("none"); $(".clearSearchContent").on("click", function () { $(".searchContent").val(""); studentName = $(".searchContent").val(); pageIndex = 1; $(".clearSearchContent").addClass("none"); $(".searchContent").focus(); }) } }); // 搜索框失去焦點(diǎn)時(shí) 如果搜索框沒有內(nèi)容則恢復(fù)搜索前狀況 如果有內(nèi)容則搜索 $(".searchContent").on("blur", function () { if ($(".searchContent").val().length == 0) { $(".searchContent").attr("placeholder", "搜索"); $(".searchContent").css("background-image", "url(./res/png/magnify.png)"); $(".cancelSearchBtn").addClass("none"); $(".searchImg").addClass("none"); } else { studentName = $(".searchContent").val(); }) //搜索框獲得焦點(diǎn)時(shí),并且搜索框有內(nèi)容的時(shí)候,出現(xiàn)打叉,打叉可以清空搜索框內(nèi)容并加載全部請(qǐng)假單 $(".searchContent").on("focus", function () { $(".searchContent").attr("placeholder", ""); $(".searchContent").css("background-image", ""); $(".searchImg").removeClass("none"); var searchContent = $(".searchContent").val(); if (searchContent.length > 0) { $(".clearSearchContent").removeClass("none"); $(".clearSearchContent").on("click", function () { $(".searchContent").val(""); }); } }); // 當(dāng)滑動(dòng)請(qǐng)假單列表時(shí) 輸入框失去焦點(diǎn) 則隱藏輸入鍵盤和填寫請(qǐng)假單的按鈕 $(document).scroll(function () { if ($(".searchContent").is(":focus")) { $(".searchContent").blur(); } }); // 點(diǎn)擊手機(jī)鍵盤的搜索/開始按鈕進(jìn)行搜索 $(document).keydown(function (event) { if (event.keyCode == 84 || event.keyCode == 13) { studentName = $(".searchContent").val(); pageIndex = 1; if (mineManagement) { inquireMyManageClassesList(pageIndex); } else { loadData(pageIndex); } } }); // 點(diǎn)擊取消 情況搜索框的輸入內(nèi)容 并加載全部請(qǐng)假單 $(".cancelSearchBtn").on("click", function () { $(".searchContent").val(""); $(".searchContent").attr("placeholder", "搜索"); $(".searchContent").css("background-image", "url(./res/png/magnify.png)") $(".cancelSearchBtn").addClass("none"); $(".searchImg").addClass("none"); studentName = ""; }); // 點(diǎn)擊搜索圖標(biāo)進(jìn)行搜索 $(".searchImg").on("click", function () { studentName = $(".searchContent").val(); pageIndex = 1; });
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
創(chuàng)建公共調(diào)用 jQuery Ajax 帶返回值
請(qǐng)求Ajax 帶返回值,并彈出提示框提醒的實(shí)現(xiàn)代碼,需要的朋友可以參考下2012-08-08JQuery通過后臺(tái)獲取數(shù)據(jù)遍歷到前臺(tái)的方法
今天小編就為大家分享一篇JQuery通過后臺(tái)獲取數(shù)據(jù)遍歷到前臺(tái)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08jquery ready函數(shù)、css函數(shù)及text()使用示例
想必大家對(duì)jquery的ready函數(shù)、css函數(shù)、text()并不陌生吧,其實(shí)很好理解的,接下來有個(gè)不錯(cuò)的示例,如果你對(duì)此理解還是很模糊可以參考下2013-09-09利用jQuery實(shí)現(xiàn)CheckBox全選/全不選/反選的簡單代碼
下面小編就為大家?guī)硪黄胘Query實(shí)現(xiàn)CheckBox全選/全不選/反選的簡單代碼。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05使用jQuery實(shí)現(xiàn)的擲色子游戲動(dòng)畫效果
大家一定都玩過擲色子的游戲,今天我給大家分享的是如何使用jQuery來實(shí)現(xiàn)擲色子的動(dòng)畫效果,通過jQuery的animate()自定義動(dòng)畫函數(shù)并結(jié)合CSS背景圖片切換實(shí)現(xiàn)的動(dòng)畫效果2014-03-03jquery ztree實(shí)現(xiàn)模糊搜索功能
這篇文章主要為大家詳細(xì)介紹了jquery ztree實(shí)現(xiàn)模糊搜索功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-02-02jquery拖動(dòng)層效果插件用法實(shí)例分析(附demo源碼)
這篇文章主要介紹了jquery拖動(dòng)層效果插件用法,結(jié)合實(shí)例形式分析了jquery-ui-1.7.2.custom.min.js插件的具體使用技巧,并附帶完整demo源碼供讀者下載參考,需要的朋友可以參考下2016-04-04jQuery發(fā)請(qǐng)求傳輸中文參數(shù)亂碼問題的解決方案
這篇文章主要介紹了jQuery發(fā)請(qǐng)求傳輸中文參數(shù)亂碼問題的解決方案,需要的朋友可以參考下2018-05-05