从 ASP.Net MVC3 (C#) 应用程序中获取此 HTML:
<div class="row-fluid">
<div class="span4">
<label for="MailPrefBusi">Business Street</label>
<input type="radio" checked="checked" class="validate[groupRequired[MailingPreference]] MailingPreference"
parent_tab="tab4" id="MailPrefBusi" name="MailingPreference" value="1">
</div>
<div class="span4">
<label for="MailPrefBusiPO">Business PO</label>
<input type="radio" class="validate[groupRequired[MailingPreference]] MailingPreference"
parent_tab="tab4" id="MailPrefBusiPO" name="MailingPreference" value="0" disabled="disabled">
</div>
<div class="span4">
<label for="MailPrefHome">Home</label>
<input type="radio" class="validate[groupRequired[MailingPreference]] MailingPreference"
parent_tab="tab4" id="MailPrefHome" name="MailingPreference" value="2">
</div>
</div>
但在浏览器、FF、IE9、IE8 和 Chrome 中查看时,MailPrefBusi 收音机未显示选中。
这是生成 HTML 的代码:
<div class="row-fluid">
@{
String busipref = "";
String popref = "";
String homepref = "";
switch (ViewBag.part.MailingPreference)
{
case 1:
busipref = "checked=\"checked\"";
break;
case 0:
popref = "checked=\"checked\"";
break;
case 2:
homepref = "checked=\"checked\"";
break;
}
}
<div class="span4">
<label for="MailPrefBusi">Business Street</label>
<input type="radio" value="1" name="MailingPreference" id="MailPrefBusi"
parent_tab="tab4" class="validate[groupRequired[MailingPreference]] MailingPreference" @Html.Raw(busipref) />
</div>
<div class="span4">
<label for="MailPrefBusiPO">Business PO</label>
<input type="radio" value="0" name="MailingPreference" id="MailPrefBusiPO"
parent_tab="tab4" class="validate[groupRequired[MailingPreference]] MailingPreference" @Html.Raw(popref) />
</div>
<div class="span4">
<label for="MailPrefHome">Home</label>
<input type="radio" value="2" name="MailingPreference" id="MailPrefHome"
parent_tab="tab4" class="validate[groupRequired[MailingPreference]] MailingPreference" @Html.Raw(homepref) />
</div>
</div>
还有这个jQuery代码:
if ($("#BusinessAddress1").val() == "") {
$("#MailPrefBusi").attr('checked', false);
$("#MailPrefBusi").attr('disabled', true);
} else {
$("#MailPrefBusi").attr('disabled', false);
if ($("#MailPrefBusi").attr('checked')) {
$("#MailPrefBusi").attr('checked', 'checked');
}
}
if ($("#HomeAddress1").val() == "") {
$("#MailPrefHome").attr('checked', false);
$("#MailPrefHome").attr('disabled', true);
} else {
$("#MailPrefHome").attr('disabled', false);
if ($("#MailPrefHome").attr('checked')) {
$("#MailPrefHome").attr('checked', 'checked');
}
}
if ($("#POAddress1").val() == "") {
$("#MailPrefBusiPO").attr('checked', false);
$("#MailPrefBusiPO").attr('disabled', true);
} else {
$("#MailPrefBusiPO").attr('disabled', false);
if ($("#MailPrefBusiPO").attr('checked')) {
$("#MailPrefBusiPO").attr('checked', 'checked');
}
}
但它仍然没有显示检查。这是此表格中非常重要的部分,该广播组必须至少检查一项。如果用户没有看到它被检查,我不确定该值是否被正确发送,或者因为我们有用户的 MailingPreference 被修改为具有空地址的值的实例,不好!
验证是使用 jQuery ValidationEngine 完成的。
我不确定这里到底发生了什么。我已经搜索了高低以找到答案,但空无一物,我尝试的一切都有相同的结果。