2012-10-17 40 views
-1

我正嘗試使用類別選項創建一個自動完成功能,但是當我通過使用catcomplete嘗試時,出現錯誤;類別選項的自動完成功能無法正常工作

  1. 類型錯誤:$ .widget不是一個函數 「本地主機/ php25/JS/jquery.ui.widget.js」 線67

  2. 類型錯誤:基地是不是構造 「本地主機/php25/js/jquery.ui.widget.js」 線67

  3. 類型錯誤:$( 「#搜索」)。catcomplete不是一個函數 「本地主機/ php25/index.php文件」 線50

這裏是我的代碼:

<html> 
<head> 
    <meta charset="utf-8"> 
    <title>Hello</title> 
    <script type="text/javascript" src="js/jquery-1.8.2.js"></script> 
    <script type="text/javascript" src="js/jquery.ui.autocomplete.js"></script> 
    <script type="text/javascript" src="js/jquery.ui.core.js"></script> 
    <script type="text/javascript" src="js/jquery.ui.position.js"></script> 
    <script type="text/javascript" src="js/jquery.ui.widget.js"></script> 

    <style type="text/css"> 
     .ui-autocomplete{ 
      padding: .2em .4em; 
      margin: .8em 0 .2em; 
      line-height: 1.5; 
     } 
    </style> 

    <script type="text/javascript"> 
     $.widget("custom.catcomplete", $.ui.autocomplete, { 
      _renderMenu: function(ul, items) { 
       var self = this, 
       currentCategory = ""; 
       $.each(items, function(index, item){ 
        if(item.category != currentCategory){ 
         ul.append("<li class='ui-category'>" + item.category + "</li>"); 
         currentCategory = item.category; 
        } 
        self._renderItem(ui, item); 
       }); 
      } 
     }); 
    </script> 

    <script type="text/javascript"> 
     $(function(){ 
      var data = [ 
       {label:"London Biggin Hill Arpt,BQH,United Kingdom",category:"airport"}, 
       {label:"Longvic Airport,DIJ,France",category:"airport"}, 
       {label:"Long Island Arpt,HAP,Australia",category:"airport"}, 
       {label:"Long Island Macarthur Arpt,ISP,United States",category:"airport"}, 
       {label:"Long Banga Airfield Arpt,LBP,Malaysia",category:"airport"}, 
       {label:"Longview,United States",category:"city"}, 
       {label:"Long Island,Australia",category:"city"}, 
       {label:"Long Banga,Malaysia",category:"city"}, 
       {label:"Long Bawan,Indonesia",category:"city"}, 
       {label:"Londrina,Brazil",category:"city"} 
      ]; 
      $('#search').catcomplete({ 
       source: data 
      }); 
     }); 
    </script> 
</head> 

<body> 
    <label for="search">Search: </label> 
    <input id="search" type="text" /> 
</body> 
</html> 

我只是寫在http://jqueryui.com/autocomplete/#categories

顯示類似我的代碼任何人都可以幫助我PLZ。

回答

0

您的JavaScript包括訂單是錯誤的。將autocomplete.js移動到腳本標記的末尾。

+0

thx爲提示,現在工作正常。我沒看過包含標籤的訂單。 –

相關問題