简体   繁体   中英

JavaScript runs in firefox, but not IE or Chrome?

I have the following JavaScript in my site :

 $(function() {
    var $cells = $("td");

    $("#search").keyup(function() {
        var val = $.trim(this.value).toUpperCase();
        if (val === "")
            $cells.parent().show();
        else {
            $cells.parent().hide();
            $cells.filter(function() {
                return -1 != $(this).text().toUpperCase().indexOf(val);
            }).parent().show();
        }
    });
});​

Link to it in action.

This example works in all browsers, so I assume the problem is with my HTML somewhere. Here is the relevant part :

  <div id="searchContainer">
                <input id="search" type="text">
            </div>
                <table>
                <tr>
                    <th>Username</th>
                    <th>Full name</th> 
                    <th>Tick to select</th>
               </tr>
           @foreach (var user in result) {
            <tr><td>@user.Username</td> <td>@user.FirstName @user.SecondName</td>
                <td><input type="checkbox" name="userId" value="@user.UserId" /></td></tr>
                }

The error I am thinking must be here since the code works perfectly in Firefox but does not run at all in Chrome or IE.

Maybe because you are missing the closing / on your input search box...

<input id="search" type="text">

should be

<input id="search" type="text" />

If not, try posting the generated source, to ensure what the client is actually seing rather than what asp.net is seeing (I'm assuming you are using Asp.net mvc with razor?).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM