以下是我的代码
HTML
<input type="submit" onclick="OpenDialog()" value="Add Record" />
<div id="AddBox" style="display: none">
<label>Install</label>
<input type="text" id="Install" />
<label>Payout</label>
<input type="text" id="Payout" />
<label>Start Date</label>
<input type="text" id="reqStartDate" value="@ViewBag.StartDate" name="reqStartDate" readonly="true" />
<label>End Date</label>
<input type="text" id="reqEndDate" value="" name="reqEndDate" readonly="true" />
</div>
JS
<script type="text/javascript">
function OpenDialog() {
$('#AddBox').dialog({
title: 'New Client',
autoOpen: false,
resizable: false,
show: {
effect: "slide",
duration: 800
},
hide: {
effect: "fold",
duration: 800
},
buttons: {
"Add":function onsave() {
$.ajax({
url: '@Url.Action("BountyMatrix", "Marketing")',
type: 'POST',
data: {
clientkey: $('#reqClientID').val(),
install: $('#Install').val(),
payout: $('#Payout').val(),
StartDate: $('#reqStartDate').val(),
EndDate: $('#reqEndDate').val()
},
success: function (data) {
alert('Success');
$('#AddBox').dialog('close');
location.reload();
},
error: function (data) {
alert('Try Again :(');
}
});
}
},
height: 370,
width: 440,
modal: false
});
var name = $('#Name').val();
var address = $('#Address').val();
$('#Dialog-Name').val(name);
$('#Dialog-Address').val(address);
$('#AddBox').dialog('open');
}
</script>
我有一个打开对话框的按钮,它包含没有表单标签的文本框,对话框中的按钮发布表单。我只想向文本框添加验证,如果这些框为空,则不应提交表单。我应该怎么做它使用 jquery 验证?