我有一个带有asp控件的网络表单,我想看看它是否被选中以显示更多信息(Checkbox1被选中所以--> div:yourDivClass显示)。但在我的页面上它不起作用 这是我的代码:
<%@ Page Title="Form" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Form.aspx.cs" Inherits="WebApplication1.Form" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<!DOCTYPE html>
<html>
<head>
<style>
.yourDivClass{
display:none;}
</style>
<script language="text\javascript">
$("#CheckBox1").change(function () {
if ($(this).attr('checked')) {
$(".yourDivClass").show();
}
});
</script>
</head>
<body>
<asp:Panel ID="Panel1" runat="server">
<table>
<tr>
<td >Do you have...?</td>
<td class="hiddenText">
<asp:CheckBox ID="CheckBox1" runat="server" />
</td>
</tr>
</table>
</asp:panel>
<div class="yourDivClass">Im Your div</div>
<table>
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="Submit" ForeColor="#FF66FF" OnClick="Button1_Click" />
</td>
<td>
<asp:Label ID="Label1" runat="server" Text="Label" Visible="false"></asp:Label>
</td>
</tr>
</table>
</body>
</html>
</asp:Content>
任何想法请
最佳答案
因为这是一个 asp 控件,所以 CheckBox1 的 ID 正在获取附加字符串。 对于客户端操作,请添加以下内容:
ClientIDMode="Static"
到你的asp控件。
你可以看一下这个例子: jQuery Selector for server side control
或者您可以尝试使用此选择器:
$("input[id$='_CheckBox1']")
看看这个有效的例子:
<ul runat="server" ClientIDMode="Static" id="DatesPickList" class="datesPickList">
$("#DatesPickList").css("background", "red");
关于javascript - 网页表单未运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37989018/