4

この関数を使用して、カーソルが通過したときに行に表示された 2 つのテーブルから各行のホバーとフォーカスを行い、各 tr のクリックにフォーカスします。正常に動作しますが、速度が低下しているため、IE に問題があり、その理由がわかりません。この関数のパフォーマンスを向上させる方法を誰か教えてもらえますか?

実際の例を確認してください: http://mainpage.ueuo.com/

function rowSelection(){
        var rows = $('.interactive tr');
        rows.click(function () {
            var i = $(this).GetIndex() + 1; // nth-child is 1-based
            rows.removeClass('selectedRow');
            rows.filter(':nth-child(' + i + ')').addClass('selectedRow');
        });
        rows.hover(function(){
            var i = $(this).GetIndex() + 1;
            rows.filter(':nth-child(' + i + ')').addClass('hoverx');
        },function(){         
            rows.removeClass('hoverx');
        });
    };

jQuery.fn.GetIndex = function(){
    return $(this).parent().children().index($(this));
}

ありがとうございました。

4

2 に答える 2

1

代わりに CSS ベースのホバーを使用できませんか? これは、すべてのブラウザ、特に IE でパフォーマンスが向上します。

.interactive tr:hover td {
    background: lime !important;
}

JavaScript/jQuery に固執したい場合は、これを取り除くことをお勧めします。

<meta http-equiv="X-UA-Compatible" content="IE=8">

これにより、IE は IE8 モードを使用するようになります。IE8 モードは IE9 モードよりも低速です。

于 2012-04-24T08:56:25.573 に答える
0

これを試して

$(document).ready(function(){

 $(".interactive tr").hover(function() {
   $(this).addClass("hoverx");
    }, function() {
   $(this).removeClass("hoverx");
  });

 $(".interactive tr").click(function() {
  $(".interactive tr.selectedRow").removeClass("selectedRow");
     $(this).addClass("selectedRow");
  });​ 
});
于 2012-04-24T08:54:29.660 に答える