<!--彈窗-->
<aside class="winbg" id="set_school" @if(!session()->has('school_id')) style="display: block;" @endif>
<div class="winbgclick"></div>
<div class="schoolcheck">
<!--<h2>選擇您所在的學(xué)校</h2>-->
<p class="box01">
<input type="submit" value="搜索" class="sub"/>
<input type="text" value="" list="school_list" id="school_name" onfocus="fuzzySearch.call(this)" placeholder="請(qǐng)輸入" class="text"/>
@if(session('school_id'))
<span onclick="$(this).parent().parent().parent().fadeOut(200);">取消</span></p>
@endif
<div class="clear h11"></div>
<section id="school_list">
@foreach($schools as $school)
<a id="school_{{$school->id}}" href="{{ $school->setSchoolLink() }}" @if(session('school_id') == $school->id) class="sel" @endif >{{ $school->name }}</a>
@endforeach
</section>
</div>
</aside>
@section('script')
@parent
<script type="text/javascript">
function fuzzySearch(e) {
const that = this;
//獲取列表的ID
let listId = $(this).attr("list");
//列表
let list = $('#' + listId + ' a');
//列表項(xiàng)數(shù)組 包列表項(xiàng)的id、內(nèi)容、元素
let listArr = [];
//遍歷列表,將列表信息存入listArr中
$.each(list, function (index, item) {
let obj = {'eleId': item.getAttribute('id'), 'eleName': item.innerHTML, 'ele': item};
listArr.push(obj);
});
//current用來(lái)記錄當(dāng)前元素的索引值
let current = 0;
//showList為列表中和所輸入的字符串匹配的項(xiàng)
let showList = [];
//為文本框綁定鍵盤(pán)引起事件
let flag = false;
let doThing = function (_this){
//列表框顯示
$('#' + listId).show();
//文本框中輸入的字符串
const searchVal = $(that).val().replace(' ', '');
showList = [];
//將和所輸入的字符串匹配的項(xiàng)存入showList
//將匹配項(xiàng)顯示,不匹配項(xiàng)隱藏
$.each(listArr, function (index, item) {
if (item.eleName.indexOf(searchVal) != -1) {
item.ele.style.display = "block";
showList.push(item.ele);
} else {
item.ele.style.display = 'none';
}
});
console.log(showList);
};
$(this).on('input propertychange', function (){
doThing(this);
});
}
</script>
@endsection
jQuery 前端搜索框
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 對(duì)于目標(biāo)標(biāo)簽的選定。使用ID或者使用CLASS名稱(chēng)。 使用ID,其點(diǎn)擊事件書(shū)寫(xiě): $("#addBtn").cli...
- 效果圖 css代碼 基本上沒(méi)什么設(shè)計(jì),能用就好。 Jquery部分 首先是獲取提示詞部分 鍵盤(pán)操作部分 當(dāng)有輸入時(shí)...
- 這個(gè)插件可以把你指定的列表在搜索框輸入的時(shí)候進(jìn)行匹配過(guò)濾,讓用戶(hù)快速找到并從預(yù)選值中選擇生產(chǎn)環(huán)境下載請(qǐng)點(diǎn)擊下載注意...
- 需求:當(dāng)點(diǎn)擊按鈕計(jì)算器時(shí),在窗口中間彈出模態(tài)框,可以計(jì)算,點(diǎn)擊x關(guān)閉模態(tài)框效果圖: 知識(shí)點(diǎn)總結(jié):1、常用html標(biāo)...
- !DOCTYPE html> 定時(shí)器彈框 .pop_con{display: none;/默認(rèn)不顯示,用定...