简体   繁体   English

jQuery无法使用ASP.NET C#与母版页一起使用

[英]Jquery is not working with Master Page using ASP.NET C#

This code works fine in .aspx page no issues. 这段代码在.aspx页面上正常工作没有问题。 but if i use master page then nothing works fine here,i tried placing the JQuery script in Master page, even then nothing is working. 但是,如果我使用母版页,那么这里没有任何工作,我尝试将JQuery脚本放置在母版页中,即使没有任何作用。 is there any thing setting need to be done here. 这里有什么需要设置的事情吗? Still not getting why info div is not loading count. 仍然无法理解为什么info div未加载计数。 Below is the link 以下是链接

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

I refer following blog also: 我也参考以下博客:

http://mwtech.blogspot.co.il/2009/04/2-ways-to-load-jquery-from-aspnet.html http://mwtech.blogspot.co.il/2009/04/2-ways-to-load-jquery-from-aspnet.html

MasterPage.master code: MasterPage.master代码:

 <head runat="server">
<title></title>

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



<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>

<form id="form1" runat="server">

 <div>
    <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

    </asp:ContentPlaceHolder>
</div>

</form>

</body>

</html>

Default2.aspx code Default2.aspx代码

 <script type="text/javascript">

     var Editor1 = '#Editor1';
     var Editor1CountLimit = 50
     var Editor1InfoArea = '#Info';

     var Editor2 = '#Editor2';
     var Editor1InfoArea1 = '#Info1';

     $(document).ready(function () {
         TrackCharacterCount(Editor1, Editor1CountLimit, Editor1InfoArea);
         TrackCharacterCount(Editor2, Editor1CountLimit, Editor1InfoArea1);
     });

     function TrackCharacterCount(ctl, limit, info) {
         var editor = $(ctl).contents().find('iframe').eq(2);
         $(editor).load(function () {
             var txt = $(this).contents().find('body').text();
             $(info).html(txt.length); //set initial value 
             $(this).contents().keyup(function () {
                 var txt = $(this).contents().find('body').text();

                 if (txt.length > limit)
                     $(info).html(txt.length).css("color", "red");
                 else
                     $(info).html(txt.length).css("color", "");
             });
         });
     }

     function ValidateEditor1Length(source, args) {
         var editor = $(Editor1).contents().find('iframe').eq(2);
         var txt = editor.contents().find('body').text();
         var isValid = txt.length > 0 && txt.length <= Editor1CountLimit;
         args.IsValid = isValid;
     }


     function ValidateEditor1Length1(source, args) {
         var editor = $(Editor2).contents().find('iframe').eq(2);
         var txt = editor.contents().find('body').text();
         var isValid = txt.length > 0 && txt.length <= Editor1CountLimit;
         args.IsValid = isValid;
     }

</script> 


      <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>

            <div id="Info">Info</div>

  <%--  <cc1:Editor ID="Editor1" runat="server" />--%>
    <cc1:Editor ID="Editor1" runat="server" />
    <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="Editor1" ClientValidationFunction="ValidateEditor1Length" ErrorMessage="Exceeded Character Limit"></asp:CustomValidator>


   <div id="Info1">Info</div>
   <%-- <cc1:Editor ID="Editor2" runat="server" />--%>
    <cc1:Editor ID="Editor2" runat="server" />
    <asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="Editor2" ClientValidationFunction="ValidateEditor1Length1" ErrorMessage="Exceeded Character Limit"></asp:CustomValidator>

</div>
<asp:Button ID="Button1" runat="server" Text="Button" />

Thank you. 谢谢。

There should be a file called jquery-1.3.2.js and/or jquery-1.3.2.min.js . 应该有一个名为jquery-1.3.2.js和/或jquery-1.3.2.min.js You need to reference one of those two. 您需要引用这两个之一。 The VSdoc file you are using is just for intellisense purposes in older versions of Visual Studio. 您正在使用的VSdoc文件仅在旧版本的Visual Studio中用于智能感知。

Your Script tag should look like this: 您的脚本标签应如下所示:

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

In addition you might want to update to a newer verison of JQuery. 另外,您可能需要更新到JQuery的较新版本。 According to Jquery.com/download , the uptodate-versions are 1.11.3 and 2.1.4 . 根据Jquery.com/download,uptodate-versions1.11.32.1.4

Inside visual Studio you can also use the package manager console to install a new version of Jquery using the following command(s): 在visual Studio中,您还可以使用软件包管理器控制台通过以下命令安装新版本的Jquery:

Install-Package jQuery
Update-Package jQuery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM