2015-05-30 53 views
0

如果我爲jQuery Tablesorter採取任何簡單的例子並在本地運行,它可以正常工作。如果我將jquery-latest的本地鏈接替換爲jquery 2.1.3的cdn鏈接,就好像jQuery尚未加載。所有你需要做的就是用
"cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"替換這個「<script type="text/javascript" src="./js/jquery-latest.js"></script>」中的src,這就像jQuery沒有加載。例如,在Tablesorter的「尋呼機」演示代碼:tablesorter.com/docs/example-pager.htmljQuery Tablesorter with jQuery 2.x

我是否缺少一些愚蠢的,明顯的,令人尷尬的問題,或者Tablesorter不能與最新的jQuery,或...?

+0

請提供一些示例代碼;這是更容易排除故障 – nomistic

+0

我是新來張貼在這裏。當我試圖將代碼複製到textarea中時,它編輯了任何看起來像html的東西。 –

+0

如果你想粘貼代碼,要麼敲擊空格鍵4次,要麼選擇整個代碼塊,然後使用ctrl-K – nomistic

回答

1

如果你看一下開發控制檯(按F12),你會看到有一個JavaScript錯誤 - 使用jQuery V1.9 +當嘗試在this demo

Uncaught TypeError: Cannot read property 'msie' of undefined

此錯誤僅出現。這是因爲尋呼機代碼使用插件的內部clearTableBody函數,該函數檢查jQuery.browser是否爲IE,並且因爲該函數在jQuery v1.9 +中完全刪除,所以會發生javascript錯誤。

所以你有三個選擇。

  1. 切換到始終使用jQuery小於v1.9。
  2. Modify the core plugin和替換此代碼:這個

    this.clearTableBody = function (table) { 
        $(table.tBodies[0]).empty(); 
    }; 
    
  3. this.clearTableBody = function (table) { 
        if ($.browser.msie) { 
         while (table.tBodies[0].firstChild) { 
          table.tBodies[0].removeChild(table.tBodies[0].firstChild); 
         } 
        } else { 
         table.tBodies[0].innerHTML = ""; 
        } 
    }; 
    

    或者,嘗試了我fork of tablesorter不使用jQuery.browser,並且具有一系列增強功能,有用的部件和解析器。令人遺憾的是,大多數小部件與原始tablesorter不兼容。

+0

哇。感謝你花了這麼多時間幫助新手。非常感謝。 –