日期:2014-05-16 浏览次数:20445 次
function getSearch(tableName,txt){
var txt = txt;
//var tableName =tableName;
if(txt == null || txt == "")
{
alert("请输入关键字");
return false;
}
//正则公式...
var re = eval("/"+txt+"/g");
//var re = new RegExp(txt);
//定义接收数组...
var result = new Array();
//数据存放的table
var tableObj = document.getElementById(tableName);
//显示出匹配内容的table
var ntableObj = document.getElementById('sch_table');
//先清空sch_table
var rcount = ntableObj.rows.length;
for(var i = rcount-1 ;i>0 ;i--)
{
ntableObj.deleteRow(i);
}
//第一行对象
var trObj = tableObj.firstChild.firstChild;
var ntrObj = ntableObj.firstChild.firstChild;
for(trObj; trObj!=null; trObj= trObj.nextSibling)
{
var tdtxt=trObj.cells[1].innerHTML;
//alert(tdtxt);
//test 只能成功一次. ?????????????????????
re.lastIndex = 0;
if(re.test(tdtxt)==true)
{
result[result.length] = trObj;
}
}
if(result.length==0){
alert("没有查询到结果");
return false
}
//搜索结果..付给接收的table
for(var i=0;i<result.length;i++)
{
ntableObj.firstChild.firstChild.appendChild(result[i]);
}
//赋予双击函数..
for(var i=0;i<result.length;i++)
{
ntableObj.firstChild.firstChild.name = 'sch_id_'+i;
}
ntableObj.firstChild.firstChild.ondblclick=function(){acq_infor(tableName);}
}