我正在为我一直在处理的表单尝试一些 JS。目的是在用户未选择"is"时隐藏。这就是我遇到的问题: 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();
}
}
});
最佳答案
<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>
<script>
$(document).ready(function () {
showHide();
$('#rbMatchingGift input').change(function () {
showHide();
});
function showHide() {
var mgift = $('#rbMatchingGift input:checked');
var shcompany = $('#shcompany');
if (mgift.val() == "1") {
shcompany.show();
} else {
shcompany.hide();
}
}
});
</script>
关于javascript - 根据选定的单选按钮隐藏显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15300638/