JS 控制文本框必须输入值才能查询
有俩文本框,必须输入其中一个才能查询
<div>
<table>
<tbody>
<tr>
<td>
<span class="min_label">ID</span>
@Html.TextBoxFor(model => model.Condition.ID, new { @class = "input_txt w130 textbox1" })
</td>
<td>
<span class="label">Name</span>
@Html.TextBoxFor(model => model.Condition.Name, new { @class = "input_txt w130 textbox2" })
<span class="field-validation-valid pnrticketno" data-valmsg-replace="true"><span class="">请填写查询条件</span></span>
</td>
</tr>
<tr>
<td colspan="3">
<input type="submit" class="btn_sub ml60 submit" value="立即查询" />
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
//移除提示
function removeError($class) {
$class.addClass("field-validation-valid").removeClass("field-validation-error"); }
//验证错误
function addError($class) {
$class.removeClass("field-validation-valid").addClass("field-validation-error"); }
//判断查询条件是否填写 移除提示信息
$(".textbox1").focus(function () {
removeError($(".pnrticketno"));
});
//点击查询 需验证的信息
$(".submit").click(function () {
if ($(".textbox1").val() == "" && $(".textbox2").val() == "") {
addError($(".pnrticketno"));
return false; } });
</script>