一个很见鬼的正则问题,高手过来看一下
if(reg.test(tr.cells[nType].innerHTML))哪个语句两次判断的条件完全一样,怎么结果就不一样呢.更见鬼的是若进行两次判断则可以得到正确的筛选结果,若去掉下面的一次判断则会漏掉一些符合条件的结果,对正则一直不太熟悉,调试了半天没找到结果,请大家帮忙看看
<html>
<head>
<title> </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
</head>
<body>
<center>
<script type= "text/javascript ">
function Search(Tbl,TextValue)
{
var count=0;
var nType=GetType();
var keyWord=TextValue.value;
var strReg= "/^ "+keyWord+ ".*?$/gi "
var reg=window.eval(strReg);
var tr;
alert(reg);
if(keyWord!= " "){
for(var i=0;i <Tbl.rows.length;i++){
tr=Tbl.rows[i];
alert(tr.cells[nType].innerHTML);//测试数据
if(reg.test(tr.cells[nType].innerHTML)){//第一次判断
alert( "[true] ");
tr.style.display= "block ";
count++;
}
else{
alert( "[false] ");
tr.style.display= "none ";
}
if(reg.test(tr.cells[nType].innerHTML))//第二次判断
alert( "true ");
else
alert( "false ");
}
}
if(count==0){
alert( '找不到你要的记录! ');
ListAll(Tbl);
}
}
function ListAll(Tbl){
for(var i=0;i <Tbl.rows.length;i++){
Tbl.rows[i].style.display= "block ";
}
}
function GetType(){
var oInputs=document.getElementsByTagName( "input ");
for(var i=0;i <oInputs.length;i++)
if(oInputs[i].type== 'radio ' && oInputs[i].checked)
return oInputs[i].value;
}
</script>
<input id= "ttt " type= "text " style= "width:200 " >
<input type= "button " value= "查找 " onClick= "Search(Tbl1,ttt) " >
<input type= "button " value= "返回 " onClick= "ListAll(Tbl1) ">
<input name= "paytype " type= "radio " value= "0 " checked >
文字
<input type= "radio " name= "paytype " value= "1 " >
数字
<input type= "radio " name= "paytype " value= "2 " >
日期
<