【发布时间】:2013-07-18 14:23:51
【问题描述】:
我有一个表单,我想在选中复选框时限制下拉列表中的数据
所以当 Is Primary 复选框被选中时,不会有 2 个电子邮件地址是 Is Primary 都是 True !!这就是我要防止的
这样当我保存时会出现一个消息窗口并让用户知道他/她选中了相同下拉值的复选框
using (Html.BeginForm("Save", "Worker", FormMethod.Post, new { id = "contactForm" }))
{
<input type="hidden" id="workerId" name="workerId" value="@workerId" />
<p>
<label for="ddlContactType">
Contact Type</label>
<span>
@Html.DropDownList("ddlContactType", new SelectList(ViewBag.ContactTypeList, "ID", "Display_Value", workerContactType), "[Please Select]",
new Dictionary<string, object>
{
{"class","validate[required] inputLong"}
})
</span>
</p>
<p>
<label for="txtContactValue">
Contact Value</label>
<span>
<input type="text" id="txtContactValue" name="txtContactValue" class="validate[required] inputLong" value="" />
<input type="checkbox" name="chkWorkerIsPrimary" id="chkWorkerIsPrimary" value="true"
checked="checked" />
<label>
Is Primary?</label>
</span>
</p>
<p>
<span>
<input type="submit" id="btnAdd" class="styledButton" value="Add" />
</span>
</p>
}
</div>
我需要用 Javascript 或 Jquery 编写的验证,但我不知道如何开始:(
谢谢
【问题讨论】:
-
您可以在复选框的点击事件上处理它。答案中的代码
标签: c# javascript jquery asp.net-mvc razor