2009-11-10 83 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" /> 
... 
相关问题