当前位置: 动力学知识库 > 问答 > 编程问答 >

JavaScript: filter the table using particular column

问题描述:

Here this is my js. I need to filter a table using this. It works correctly but. When the control come out of function the table came back to normal form without filter, i make sure this by the help of alert() in end of function.. when alert shows the table seams to be clearly sorted. when it get out of function table come back to its normal data

function search (tableid)

{

var table = document.getElementById(tableid).tBodies[0];

var mt = (document.getElementById("srchMsgType").value).trim().toLowerCase();

var ele;

for (var r = 1; r < table.rows.length; r++)

{

ele = table.rows[r].cells[4].innerHTML.trim();

if (ele.toLowerCase().indexOf(mt)==0 )

{

table.rows[r].style.display = '';

}

else

{

table.rows[r].style.display = 'none';

}

}

alert();

}

for eg expected output is

when i/p is 8

no mt

1 8

2 8

4 8

During alert messgae display time it works as if the above expected answer.asfter clicking ok to it

answer is

no mt

1 8

2 8

3 10

4 8

5 25

分享给朋友:
您可能感兴趣的文章:
随机阅读: