【发布时间】:2017-04-26 16:04:34
【问题描述】:
该功能在 Firefox 中不起作用,但在 Chrome 和 Internet Explorer 以及 Micrisoft Edge 中有效,请帮助
function myFunctionN()
{
var filter = event.target.value.toUpperCase();
var rows = document.querySelector("#tablenew").rows;
for (var i = 1; i < rows.length; i++) {
var firstCol = rows[i].cells[0].textContent.toUpperCase();
var secondCol = rows[i].cells[1].textContent.toUpperCase();
var thirdCol = rows[i].cells[2].textContent.toUpperCase();
var fourtCol = rows[i].cells[3].textContent.toUpperCase();
var fiftCol = rows[i].cells[4].textContent.toUpperCase();
if (firstCol.indexOf(filter) > -1
|| secondCol.indexOf(filter) > -1
|| thirdCol.indexOf(filter) > -1
|| fourtCol.indexOf(filter) > -1
|| fiftCol.indexOf(filter) > -1
)
{
rows[i].style.display = "";
} else {
rows[i].style.display = "none";
}
}
}
html/php 代码,这里没有数据,因为它在 DB echo fetch_data 正在读取到表中
<input type="text" id="myInput" onkeyup="myFunctionN()" placeholder="Search For Anything.." title="Type, What Ever You Looking For">
<div class="table-responsive">
<table id="tablenew" class="table table-bordered">
<tr>
<th width="5%">ID</th>
<th width="30%">Name</th>
<th width="10%">Gender</th>
<th width="45%">Designation</th>
<th width="10%">Age</th>
</tr>
<?php
echo fetch_data();
?>
</table>
<br />
</div>
【问题讨论】:
-
您使用的是 Firefox、Chrome 和 Edge 的哪个版本?
-
控制台的错误是什么?
event这里是什么? -
您似乎在使用
event而不定义它。将其用作这样的参数:function myFunctionN(event){…}。 -
如果您能包含相关的 HTML 会有所帮助,这样我们就可以自己测试了
-
Firefox 53.0、Chrome 58、Edge 38、IE 11。我没有收到任何错误,只是无法正常工作。应该过滤表格,但它什么也不做。
标签: javascript function google-chrome firefox