我试图根据选择单选按钮来显示隐藏图像。但似乎jQuery脚本从未激发选择变化。我的代码看起来像下面单选按钮选择更改事件不在MVC中触发
@Html.Label("Select Chart Type")
@Html.RadioButton("rbChartType", "1", isChecked: true) @Html.Label("Chart1")
@Html.RadioButton("rbChartType", "2", isChecked: false) @Html.Label("Chart2")
<img src="@Url.Action("GetChart1")" alt="Billing Graph" class="img-responsive" id="imgChart1" />
<img src="@Url.Action("GetChart2")" alt="Usage Graph" class="img-responsive" id="imgChart2" style="visibility:hidden" />
脚本
$(document).ready(function() {
$("input[name='rbChartType']").change(function() {
alert('hi');
var selectedRadio = $("input[name='rbChartType']:checked").val();
if (selectedRadio == 1) {
$('#imgChart1').show();
$('#imgChart2').hide();
}
else {
$('#imgChart1').hide();
$('#imgChart2').show();
}
});
});
我看不到我的警告射击了!
在调试器控制台的任何错误? – Dandy
这是回答您的问题吗? http://stackoverflow.com/questions/4202799/radio-button-change-event –
@devlin,这是我已经试过的例子;我不知道我在做什么错误,但那个也没有工作!我需要在单选按钮周围有一个表单吗?我也尝试过,但它没有工作 – techspider