【问题标题】:TypeError: $ is not a function error in .aspx pageTypeError: $ is not a function error in .aspx 页面
【发布时间】:2015-03-26 07:51:19
【问题描述】:

我已经在我的 asp.net 主文件中添加了 jquery.min.js 文件,并且我正在将相同的母版页添加到我的子 .aspx 页面中,但是我收到了这个错误

  `TypeError: $ is not a function
  -$(document).ready(function () {`

当我将 jquery 引用文件添加到母版页时,我无法找出为什么会出现此错误:

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

这里是我使用 jquery 的地方:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">&nbsp;  

<script type="text/javascript">

 var dateFrom = null;
 var dateto = null;
 var empID = null;

 $(document).ready(function () {

     $("#Button1").click(function () {   // On button click we must show the grid

         dateFrom = $("#TextBox4").val();
         dateto = $("#TextBox5").val();
         empID = $("#TextBox1").val();

         $("#UsersGrid").GridUnload();   // Unload the table before loading grid. This will clear the previously loaded UI in grid. Because in JQgrid UI is built at run time.
         gridload();                     // Call the function to load the grid
     });

 });

【问题讨论】:

  • 你在哪里包括jQuery?在脚本中使用它之前是否包含它?
  • 你应该在你的 Jquery 脚本之前包含 jquery Lib
  • @PaulTomkiel 我将 jQuery 包含到母版页中,并将该母版页引用到子页中。
  • 向我们展示您生成的 HTML
  • Master PageChild Page 在同一 directory 中?

标签: c# jquery asp.net .net


【解决方案1】:

把你的库放在脚本标签之前,像这样:

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

【讨论】:

    【解决方案2】:

    您可以在母版页中使用以下代码。

     <asp:ScriptManager runat="server">
         <Scripts>                                
             <asp:ScriptReference Name="jQuery.js" Assembly="System.Web" Path="js/jquery-1.4.2.min.js" />
        </Scripts>
    </asp:ScriptManager>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      • 2018-12-13
      • 2018-05-17
      • 2021-10-08
      • 2023-03-21
      • 2018-05-09
      • 2017-08-01
      相关资源
      最近更新 更多