js實現使用者模糊查詢,相容IE、FF以及chrome

來源:互聯網
上載者:User

聊天的時候,要是好友太多了,尋找起來很不容易。這時候,放置一個使用者搜尋地區,是非常必要的。實現這個功能,用js寫上幾行即可搞定。。。

一:

點擊搜尋區,輸入查詢內容,即可查詢符合需求的使用者列表

二:

源碼如下:

//search user dml@ 2012.9.19function goSearch(s) {if (s == '') {document.getElementById('userSearchArea').style.display = 'none';return;}var o;var ss;var iLen = 5;for (i = 0; i < iLen; i++) {o = document.getElementById("d" + (i + 1));ss = innerText(o);if (ss.indexOf(s) != -1) {o.style.display = "block";} else {o.style.display = "none";}}document.getElementById('userSearchArea').style.display = '';}//document.all 只能在IE或IE核心的瀏覽器有效function innerText(o) {return document.all ? o.innerText : o.textContent;}

需要注意的是,使用者顯示區需按照指定id和class標註

<tr height="3%"><td colspan="2"><input type="text" id="querybox"value="輸入帳號,姓名等進行查詢" title="輸入帳號,姓名等進行查詢"style="width:100%;color: gray" onfocus="clearText(this)"onblur="renewText()" onkeyup="goSearch(this.value)"></td></tr><div id="userSearchArea"><div id="d1" class="bs" style="display: block; "><a href="#" onclick="return userClicked(this,'JS_ImTest');">JS_ImTest<br> </a></div><div id="d2" class="bs" style="display: block; "><a href="#" onclick="return userClicked(this,'JS_ImTestPwd');">JS_ImTestPwd<br> </a></div><div id="d3" class="bs" style="display: none; "><a href="#" onclick="return userClicked(this,'3333');" class="rosterUserSelected">3333<br> </a></div><div id="d4" class="bs" style="display: block; "><a href="#" onclick="return userClicked(this,'system');">system<br> </a></div><div id="d5" class="bs" style="display: block; "><a href="#" onclick="return userClicked(this,'test@jointsky');">test<br> </a></div></div>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.