大佬教程收集整理的这篇文章主要介绍了如何通过jquery在show / hide上启用/禁用不显眼的验证?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
–
当从下拉列表中进行选择时,我正在切换某些字段的显示.我还需要切换验证.
viewmodel.cs:
public int ddlTypeID { get; set; } public Dictionary<int,string> ddlTypes { get; set; } [required(ErrorMessageResourceName = "msgrequired",ErrorMessageResourceType = typeof(Resources.Globals))] public DateTime firstDate {get; set;} [required(ErrorMessageResourceName = "msgrequired",ErrorMessageResourceType = typeof(Resources.Globals))] public DateTime otherDate {get; set;}
Create.cshtml:
<script type="text/javascript"> $(document).ready(function () { $('.optional').hide(); $('#ddlTypeID').change(function () { var id = $(this).val(); if (id == 1) { $('.optional').show(); } else { $('.optional').hide(); } }); }); </script> @using (Html.BeginForm()) { <div class="editor-field"> @Html.DropDownListFor(x=>x.ddlTypeID,new SelectList(Model.ddlTypes,"Key","Value",Model.ddlTypeID),Resources.Globals.msgType) @Html.ValidationMessageFor(model => model.ddlTypeID) </div> <div class="editor-label"> @Html.LabelFor(model => model.firstDate ) </div> <div class="editor-field"> @Html.EditorFor(model => model.firstDate ) @Html.ValidationMessageFor(model => model.firstDate ) </div> <div class="editor-label optional"> @Html.LabelFor(model => model.otherDate ) </div> <div class="editor-field optional"> @Html.EditorFor(model => model.otherDate ) @Html.ValidationMessageFor(model => model.otherDate ) </div> <input type="submit" value="Save" /> }
以上是大佬教程为你收集整理的如何通过jquery在show / hide上启用/禁用不显眼的验证?全部内容,希望文章能够帮你解决如何通过jquery在show / hide上启用/禁用不显眼的验证?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。