私が取り組んでいるフォームの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();
}
}
});