【发布时间】:2013-03-08 18:16:36
【问题描述】:
我正在为我一直在研究的表单尝试一些 JS。如果他们的用户没有选择是,目的是隐藏。这是我坚持的一些地方: HTML:
<asp:RadioButtonList runat="server" ID="rbMatchingGift" ClientIDMode="Static">
<asp:ListItem Value="0" Text="No"></asp:ListItem>
<asp:ListItem Value="1" Text="Yes"></asp:ListItem>
</asp:RadioButtonList>
<li id="shcompany">
<label for="txtCompanyName">Company Name</label>
<asp:TextBox runat="server" ID="txtCompanyName" CssClass="narrow" />
<label for="txtCompanyPhone">Company Phone Number</label>
<asp:TextBox runat="server" ID="txtCompanyPhone" CssClass="narrow" />
</li>
JS:
$(document).ready(function () {
var shcompany = $('#shcompany');
showHide();
mgift.change(function () {
showHide();
});
function showHide() {
var mgift = $('#rbMatchingGift');
var shcompany = $('#shcompany');
if (mgift.val() == "1") {
shcompany.show();
} else {
shcompany.hide();
}
}
});
【问题讨论】:
-
您的问题到底是什么?什么不起作用?
-
在您的页面上(运行/查看后),右键单击,查看源代码。您将看到 RadioButtonList 在呈现为 HTML 后看起来非常不同。
-
@tgolisch 正如他所写的
ClientIDMode="Static",所以 id 不会改变。
标签: javascript jquery asp.net html