2009-11-10 77 views
1

我希望你能幫助我。jquery自動完成功能在localhost上不起作用

我在localhost aspx頁面上使用了下面的代碼,所以它自動完成。

它工作完美。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
    <script src="http://code.jquery.com/jquery-latest.js"></script> 
    <link rel="stylesheet" href="http://dev.jquery.com/view/trunk/plugins/autocomplete/demo/main.css" type="text/css" /> 
    <link rel="stylesheet" href="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.css" type="text/css" /> 
    <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/lib/jquery.bgiframe.min.js"></script> 
    <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/lib/jquery.dimensions.js"></script> 
    <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js"></script> 
    <script> 
    $(document).ready(function(){ 
    var data = "Core Selectors Attributes Traversing Manipulation CSS Events Effects Ajax Utilities".split(" "); 
$("#example").autocomplete(data); 
    }); 
    </script> 

</head> 
<body> 
    API Reference: <input id="example" /> (try "C" or "E") 
</body> 
</html> 

*但是,當我下載腳本等,並在我的本地服務器上運行(參見下面的代碼),這是行不通的,它並沒有給我任何錯誤 頁面確實需要約10秒加載(而不是< 1秒)

自動完成功能在頁面上不起作用,但其他所有功能都不起作用。

誰能告訴我我做錯了什麼?有什麼我必須額外打開本地或下載?

我對此非常感興趣,所以感謝您的光臨。

此外,我想數據來自一個文件,而不是可變數據。

我已經下載了所謂的「jQuery的1.3.2.min.js」以及和把它放在同一目錄中的其他腳本文件...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<%@ Page Language="C#" %> 
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> 

<head runat="server"> 
<meta content="es" http-equiv="Content-Language" /> 
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
<title>Search POL-POD</title> 
    <style type="text/css"> 
     .tahoma_small { 
      font-family: Tahoma; 
      font-size: x-small; 
     } 
    </style> 
     <script src="../autocomplete/jquery-latest.js"></script> 
      <link rel="stylesheet" href="../autocomplete/jquery.autocomplete.css" type="text/css" /> 
      <script type="text/javascript" src="../autocomplete/jquery.autocomplete.js"></script> 
      <script> 
       $(document).ready(function() { 
        var data = "Core Selectors Attributes Traversing Manipulation CSS Events Effects Ajax Utilities".split(" "); 
        $("#txtfirst").autocomplete(data); 
        $("#txtsecond").autocomplete(data); 
       }); 
      </script> 



    </head> 



    <body> 

    <form id="form1" runat="server" enableviewstate="False" autocomplete="True"> 
     POL 
     <asp:TextBox id="txtfirst" runat="server"></asp:TextBox> 
    &nbsp; POD&nbsp; 
     <asp:TextBox id="txtsecond" runat="server"></asp:TextBox> 
    &nbsp; 
     <asp:Button id="Button1" runat="server" Text="Button" /> 
     <br /> 

....etc 
+0

驗證與螢火蟲(Net標籤)所有必需的JavaScript文件中找到。 – 2009-11-10 09:28:01

+0

我正在使用Visual Web Developer 2008 ...你提到的Firebug(Net標籤)在哪裏?對不起,我的經驗不足 – frank2009 2009-11-10 09:35:57

+2

看看Firebug:http://getfirebug.com/ – Frankie 2009-11-10 09:39:24

回答

1

首先要做的是在使用jquery的任何其他腳本文件之前將文件jquery-1.3.2.min.js包含到您的文檔中,除非這是jquery-latest.js。

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

你沒有得到任何JavaScript錯誤?

+0

嗨,我已添加以下內容: 仍然無效。 不,我沒有得到任何javascript錯誤。 – frank2009 2009-11-10 09:34:46

0

如上所述,確保加載了必要的JavaScript文件。由於您使用的是ASP.NET編碼,因此您可能需要使用ResolveUrl來確保正確引用這些文件,而與請求的頁面位置無關。

<script src="<%# ResolveUrl("~/autocomplete/jquery-latest.js") %>" type="text/javascript"></script> 
<script src="<%# ResolveUrl("~/autocomplete/jquery.autocomplete.js") %>" type="text/javascript"></script> 
+0

感謝您的評論,但它給了我一個錯誤。 經過幾個小時的測試和在互聯網上搜索後,我使它工作 – frank2009 2009-11-10 12:37:50

+0

那麼它有什麼問題?什麼是正確的代碼? – 2009-11-14 14:07:43

1

終於在經過大量的測試/搜索後,我找到了一個解決方案。

無論如何,感謝您的幫助!

我上的所有環節拿出 「../」:

所以:<script src="../autocomplete/jquery.autocomplete.js"></script>

現在是:<script src="autocomplete/jquery.autocomplete.js"></script>

因此,這裏是所有的代碼(你需要的。 js和.css文件在「autocomplete」目錄中提到,以便工作)

我希望它可以幫助別人!

順便說一句,我有一個總的變量「城市」,並在.aspx頁面1200個城市僅20Kb大小

我使用.csv文件導入數據也測試了,但花了幾個加載...有數值的時間。aspx頁面是快如閃電和頁面仍然是相當小的(這顯然不是一個好主意,如果你有幾千個值)

 ... 
    </style> 

     <script src="autocomplete/jquery-1.3.2.min.js" type="text/javascript"></script> 
     <script src="autocomplete/jquery.autocomplete.js" type="text/javascript"></script> 
     <link href="autocomplete/jquery.autocomplete.css" rel="stylesheet" type="text/css" /> 

      <script> 
       $(document).ready(function() { 
         // datavalues is the array containing all the options...the .split(","); at the end means each option is separated by a comma, 
         var cities= "Madrid,Paris, Barcelona,Rome,London".split(","); 
         $("#txtfromcity").autocomplete(cities); 
         $("#txttocity").autocomplete(cities); 
        }); 
      </script> 
</head> 

<body> 


<form id="form1" runat="server" enableviewstate="False" autocomplete="True"> 
POL 
<asp:TextBox id="txtfromcity" runat="server"></asp:TextBox> 
&nbsp; POD&nbsp; 
<asp:TextBox id="txttocity" runat="server"></asp:TextBox> 
&nbsp; 
<asp:Button id="Button1" runat="server" Text="Button" /> 
... 
相關問題