gpt4 book ai didi

Jquery 脚本在母版页中不起作用

转载 作者:行者123 更新时间:2023-12-01 06:24:24 25 4
gpt4 key购买 nike

此代码在 .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>

如有任何帮助,我们将不胜感激

谢谢

最佳答案

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

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

关于Jquery 脚本在母版页中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8534777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com