我之前也有类似的问题,但我不得不修改它,因为用户改变了主意。我正在写一个脚本,如果选项0被选中,它应该显示“提醒”,否则保持隐藏。如果选择了选项2,它应该取消隐藏"cc“,否则保持隐藏状态。我的问题是,一旦事件被触发,无论是选项0还是2,这两个区域都会打开。我只是想知道我能不能让他们分开工作。下面是JS:
$('#rbPType').change(function () {
var op1 = $(this).attr('value', '0');
var op2 = $(this).attr('value', '2');
if (op1) {
$('#remind').fadeIn();
} else {
$('#remind').fadeOut();
}
$(this).change(function () {
$('#remind').toggle();
});
if (op2) {
$('#cc').fadeIn();
} else {
$('#cc').fadeOut();
}
$(this).change(function () {
$('#cc').toggle();
});
});HTML
<div class="another">
<label for="rbPType">Select One</label>
<asp:RadioButtonList runat="server" ID="rbPType" ClientIDMode="Static">
<asp:ListItem Value="0" Text="1"></asp:ListItem>
<asp:ListItem Value="1" Text="2"></asp:ListItem>
<asp:ListItem Value="2" Text="3"></asp:ListItem>
</asp:RadioButtonList>
</div>
<div id="remind">
<label for="ddlReminderMonth">Remind Me</label>
<asp:DropDownList runat="server" ID="ddlReminderMonth" AppendDataBoundItems="true" AutoPostBack="false" />
</div>
<div id="cc">
<label for="ddlReminderMonth">Remind Me Two</label>
<asp:DropDownList runat="server" ID="ddlReminderMonth" AppendDataBoundItems="true" AutoPostBack="false" />
</div>发布于 2013-03-26 02:28:09
不能有两个具有相同ddlReminderMonth的下拉列表。
您的控件在单击后会出现和消失,因为要进行切换。切换会让你的代码变得非常混乱。
<div class="another">
<label for="rbPType">
Select One</label>
<asp:RadioButtonList runat="server" ID="rbPType" ClientIDMode="Static">
<asp:ListItem Value="0" Text="1"></asp:ListItem>
<asp:ListItem Value="1" Text="2"></asp:ListItem>
<asp:ListItem Value="2" Text="3"></asp:ListItem>
</asp:RadioButtonList>
</div>
<div id="remind">
<label for="ddlReminderMonth">
Remind Me</label>
<asp:DropDownList runat="server" ID="ddlReminderMonth1" AppendDataBoundItems="true"
AutoPostBack="false" />
</div>
<div id="cc">
<label for="ddlReminderMonth">
Remind Me Two</label>
<asp:DropDownList runat="server" ID="ddlReminderMonth2" AppendDataBoundItems="true"
AutoPostBack="false" />
</div>
<script>
$('#rbPType').change(function () {
var value = $('#rbPType input:checked').val();
if (value == '0') {
$('#remind').fadeIn();
$('#cc').fadeOut();
}
else if (value == '1') {
// Show or hide
}
else { // value == '2'
$('#remind').fadeOut();
$('#cc').fadeIn();
}
});
</script>发布于 2013-03-26 02:17:48
我认为你在这里写了很多不必要的代码。jquery切换使用布尔型参数,如果为true,则显示选定的字段,如果为false,则隐藏该字段。
$('#rbPType').change(function () {
var op1 = $(this).attr('value', '0');
var op2 = $(this).attr('value', '2');
$('#remind').toggle(op1);
$('#cc').toggle(op2);
});这就是你要找的东西吗?
https://stackoverflow.com/questions/15621768
复制相似问题