使用 jQuery 查找 DetailsView 控件(编辑模板)
我有一个包含以下代码的详细信息视图:
<asp:TemplateField HeaderText="">
<EditItemTemplate>
Approve: <asp:CheckBox runat="server" ID="chkApproved" CssClass="btnStatus" />
Reject: <asp:CheckBox runat="server" ID="chkReject" CssClass="btnStatus"/>
Cancel: <asp:CheckBox runat="server" ID="chkCancel" CssClass="btnStatus" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Justification">
<EditItemTemplate>
<asp:TextBox runat="server"
id="txtJustification"
TextMode="multiLine"
width = "100%"
ReadOnly="true"
Height="5em"
/>
</EditItemTemplate>
</asp:TemplateField>
我正在尝试运行以下 jQuery,但它不起作用:
<script type="text/javascript">
$(document).ready(function () {
$("[id$='txtJustification']").hide();
$("[ID$='chkReject']").click(function () {
alert("reject");
});
})
</script>
此代码隐藏了文本框,但是当我单击“拒绝”复选框时它不起作用。我也尝试过以下方法但无济于事:
<script type="text/javascript">
$(document).ready(function () {
$("[id$='txtJustification']").hide();
$(".btnStatus").click(function () {
alert("reject");
});
})
</script>
似乎缺少什么?
I have a details view that contains the following code:
<asp:TemplateField HeaderText="">
<EditItemTemplate>
Approve: <asp:CheckBox runat="server" ID="chkApproved" CssClass="btnStatus" />
Reject: <asp:CheckBox runat="server" ID="chkReject" CssClass="btnStatus"/>
Cancel: <asp:CheckBox runat="server" ID="chkCancel" CssClass="btnStatus" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Justification">
<EditItemTemplate>
<asp:TextBox runat="server"
id="txtJustification"
TextMode="multiLine"
width = "100%"
ReadOnly="true"
Height="5em"
/>
</EditItemTemplate>
</asp:TemplateField>
I am trying to run the following jQuery and it is not working:
<script type="text/javascript">
$(document).ready(function () {
$("[id$='txtJustification']").hide();
$("[ID$='chkReject']").click(function () {
alert("reject");
});
})
</script>
This code is hiding the textbox, however it is not working when I click the Reject checkbox. I have also tried the following but with no avail:
<script type="text/javascript">
$(document).ready(function () {
$("[id$='txtJustification']").hide();
$(".btnStatus").click(function () {
alert("reject");
});
})
</script>
What seems to be missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将脚本标签放在代码末尾。
Try putting the script tag in the end of the code.
最后一个
}) 缺少分号,这应该是 });
Semicolon missing in the last
}) this should be });