JS正则检索数据,不区分大小写


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS正则检索数据,不区分大小写</title>

<input type="text" id="text1" />
<button id="btn1">检索</button><hr>
<div id="div1"></div>
<script type="text/javascript">
(function(){
/////////////////////////////////////
    var str=["Km tIshis his","isukmu uuu","iiiKMiSthtt hh","ISkkkM"];
    var text1=document.getElementById('text1');
    var btn1=document.getElementById('btn1');
    var div1=document.getElementById('div1');
    var temp='',pp,result;
    btn1.onclick=function(){
        div1.innerHTML='';
        var key=text1.value;
        //alert(key);
        for(var i=0;i<str.length;i++){
            pp=eval('/'+key+'/i');
            result=str[i].match(pp);
            if(null!=result){
                temp+=(str[i].replace(result,'<font color=red>'+result+'</font>'));
                temp+='<hr>';
            }
        }
        div1.innerHTML=temp;
    }
/////////////////////////////////////
})();


</script>



程序运行结果如下,点击这里亲自运行看看