【问题标题】:Function doesnt work in Firefox but works in Chrome功能在 Firefox 中不起作用,但在 Chrome 中起作用
【发布时间】: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>  

error picture

【问题讨论】:

  • 您使用的是 Firefox、Chrome 和 Edge 的哪个版本?
  • 控制台的错误是什么? event 这里是什么?
  • 您似乎在使用event 而不定义它。将其用作这样的参数:function myFunctionN(event){}
  • 如果您能包含相关的 HTML 会有所帮助,这样我们就可以自己测试了
  • Firefox 53.0、Chrome 58、Edge 38、IE 11。我没有收到任何错误,只是无法正常工作。应该过滤表格,但它什么也不做。

标签: javascript function google-chrome firefox


【解决方案1】:

@Xufox - 你的态度真的很糟糕,但你在那个事件的事情上走在了正确的轨道上......我不是程序员,所以你说的方式对我没有任何意义,但是在尝试了五百次之后不同的组合:)终于明白了,所以@Xufox...基本上在脚本函数myFunction04(event)中添加了事件,在html onkeyup="myFunction04(event)"中添加了事件...问题解决了。谢谢你

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多