国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

利用js 進行輸入框自動匹配字符的小例子

2019-11-20 22:35:45
字體:
來源:轉載
供稿:網(wǎng)友
html
復制代碼 代碼如下:

<p><span style="font-size: 18px; ">輸入框自動匹配字符~</span></p><p><span style="font-size: 18px; ">但是遇到一個問題~所有匹配的字符要事先寫好~大概如果是大型網(wǎng)站的話~應該是利用數(shù)據(jù)庫的記錄吧</span></p><p><span style="font-size: 18px; ">看代碼</span></p>

html
復制代碼 代碼如下:

<style>
ul,li{margin: 0; padding: 0;width:100%;}
</style>
<script language="javascript" type="text/javascript">
function checkword()
{
   var wordvalue=document.getElementById("word").value.toLowerCase();
   var alltxt="all|big|cut|car/|daph8|eeg|egg|eat|fuck|fuck you|fix|good|hand|hidden|ill|jack|jad|kevin|long|man|number|oio|part|pp|quit|QQ|rest|reg|set|submit|time|tag|uuzo|view|windows|want|xy|xun|young|yuyu|z|David|David|哈哈|";//這里就是你所想要匹配的字符,可惜只能用于小型的論壇
   var alltxtalltxtpp=alltxt.toLowerCase();
   var alltxtalltxt_xiang=alltxt.split("|");
   var alltxt_xiang1=alltxtpp.split("|");
   var inhtml="<ul>"
   var isyou=0;
   for (i=0;i<alltxt_xiang1.length;i++)
   {
       if (alltxt_xiang1[i].substr(0,wordvalue.length)==wordvalue)
       {
           inhtmlinhtml=inhtml+"<li onclick=/"document.getElementById('word').value=this.innerHTML;document.getElementById('showmenu').style.display='none';/" onmouseover=/"this.style.backgroundColor='#666666'/" onmouseout=/"this.style.backgroundColor=''/">"+alltxt_xiang[i]+"</li>";
           isyou=1;
       }
   }
   inhtmlinhtml=inhtml+"</ul>";
   if (isyou==1)
   {
       document.getElementById("showmenu").innerHTML=inhtml;
       document.getElementById("showmenu").style.display="";
   }
   else
   {
       document.getElementById("showmenu").innerHTML="";
       document.getElementById("showmenu").style.display="none";
   }
   if (wordvalue=="")
   {
       document.getElementById("showmenu").innerHTML="";
       document.getElementById("showmenu").style.display="none";
   }
}
</script>
<input type="text" name="word" size="20" id="word" onkeyup="checkword()" style="border:1px solid #666666;width:200px;height:25px;">
<div style="position: absolute; width: 200px; height: 100px; z-index: 1; left: 10px; top: 40px;border:1px solid #666666;display:none;" id="showmenu"></div>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 瑞安市| 福贡县| 辉南县| 万宁市| 平凉市| 黄浦区| 綦江县| 周宁县| 阿拉尔市| 永平县| 左云县| 万宁市| 宁津县| 新化县| 五家渠市| 徐水县| 鲜城| 澄城县| 阳信县| 阿荣旗| 原阳县| 洞头县| 金秀| 四会市| 昌邑市| 门源| 瓮安县| 平乡县| 龙泉市| 东乡族自治县| 西安市| 金坛市| 宜兴市| 龙海市| 广汉市| 铁岭县| 南郑县| 古交市| 永川市| 汾西县| 凤城市|