Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery脚本在母版页中不工作_Jquery_Asp.net - Fatal编程技术网

Jquery脚本在母版页中不工作

Jquery脚本在母版页中不工作,jquery,asp.net,Jquery,Asp.net,此代码在.aspx页面中运行良好,没有问题。但如果我使用母版页,那么这里没有什么好用的 我试着将JQuery脚本放在母版页中,即使没有任何效果。这里有什么需要做的事情吗 <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Untitled Page</title> <script src="jquery-1.6.

此代码在.aspx页面中运行良好,没有问题。但如果我使用母版页,那么这里没有什么好用的

我试着将JQuery脚本放在母版页中,即使没有任何效果。这里有什么需要做的事情吗

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <script src="jquery-1.6.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function() 
    {
     $('#<%= CheckBox1.ClientID %>').change(function() 
    {    
     if($(this).is(':checked')) 
     {       
      $("#divControlGroup").css("display", "block");   
      $("#ddlcounty option:first").attr("selected", true); 
      } 
     else 
        { 
    $("#divControlGroup").css("display", "none"); 
     } 
        })
        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <table>
        <tr>
            <td>
                <asp:CheckBox ID="CheckBox1" runat="server" Checked="false" />
            </td>
            <td>
                <div id="divControlGroup" runat="server">
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                    <asp:DropDownList ID="ddlcounty" runat="server">
                      <asp:ListItem Value="0">Select</asp:ListItem>
                        <asp:ListItem Value="1">India</asp:ListItem>
                        <asp:ListItem Value="2">US</asp:ListItem>
                        <asp:ListItem Value="3">UK</asp:ListItem>
                    </asp:DropDownList>
                </div>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
任何帮助都将被告知


谢谢

将母版页脚本引用更改为使用ResolveUrl,并将脚本放入正在使用的ContentPlaceHolder中:

 <script src='<%= Page.ResolveUrl("~/jquery-1.6.2.min.js")' type="text/javascript"></script>

 //script related to the specific page needing ClientID refs
 <asp:Content ID="Content2" ContentPlaceHolderID="Content" Runat="Server" >
    <script>....</script>
</asp:content>

将母版页脚本引用更改为使用ResolveUrl,并将脚本放入正在使用的ContentPlaceHolder中:

 <script src='<%= Page.ResolveUrl("~/jquery-1.6.2.min.js")' type="text/javascript"></script>

 //script related to the specific page needing ClientID refs
 <asp:Content ID="Content2" ContentPlaceHolderID="Content" Runat="Server" >
    <script>....</script>
</asp:content>

如果您使用的是母版页和内容占位符,请使用以下内容: $divControlGroup将不起作用。您需要像前面一样在代码中使用clientID


内容占位符被添加到ID中,这就是它不匹配的原因。

如果您使用的是母版页和内容占位符,例如: $divControlGroup将不起作用。您需要像前面一样在代码中使用clientID


内容占位符被添加到ID中,这就是它不匹配的原因。

您能描述一下您看到的错误吗?从母版页到jQuery文件jQuery-1.6.2.min.js的路径是否可能不正确?您给了jQuery一个相对路径。尝试绝对路径。如果使用if typeof jQuery===未定义{alertjQuery not loaded;}启动脚本,会发生什么情况;你能描述一下你看到的错误吗?从母版页到jQuery文件jQuery-1.6.2.min.js的路径是否可能不正确?您给了jQuery一个相对路径。尝试绝对路径。如果使用if typeof jQuery===未定义{alertjQuery not loaded;}启动脚本,会发生什么情况;