0
这是一个MVC项目,它有几个文本框和一个复选框。未选中时,所有的文本框都是必需的。选中时,其中一个文本框被禁用且不需要,而其他文本框仍然需要。红色边框和必需的错误消息不会消失与.rules("remove","required")
我添加了一些CSS来更改边框的颜色,但我无法弄清楚如何摆脱错误消息。JQuery验证删除必需的标记暂时
模型视图
[Required(ErrorMessage="Required")]
public string textBox2{ get; set; }
[Required(ErrorMessage="Required")]
public string textBox3{ get; set; }
简明剃刀HTML
@Html.CheckBoxFor(model => model.checkBox)
@Html.TextBoxFor(model => model.textBox1, new { @class = "disabledTrue" })
@Html.TextBoxFor(model => model.textBox2)
@Html.TextBoxFor(model => model.textBox3)
CSS禁用红色边框,颜色变为浅灰色
.disabledTrue.input-validation-error:disabled {
border-color:lightgray;
}
JQuery的
$(document).ready(function() {
$('#textBox1').rules("add", "required");
$('#checkBox').click(function() {
//makes the input unrequired
$('#textBox1').rules("remove", "required");
});
});