我想對所有三個標記進行表單驗證,驗證後啓用提交按鈕,直到驗證完成,不啓用提交按鈕。如何做jQuery表單在提交之前驗證html元素
<html>
<head>
<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" href="css/datepicker.css" />
<link rel="stylesheet" href="css/mystyle.css" />
<script src="js/jquery-2.2.2.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/moment.js"></script>
</head>
<body>
<form id="report-form">
<div id="report-pane" class="row">
<div class="col-xs-1">
<label>Report:</label>
</div>
<div class="col-xs-2">
<select class="form-control" id="report">
<option value="" selected>Select Report</option>
<option id="rep1" value="10">Report 1</option>
<option id="rep2" value="20">Report 2</option>
<option id="rep3" value="30">Report 3</option>
</select>
</div>
</div>
<!--Date Section-->
<div id="date-pane" class="row">
<!--Script for datepicker-->
<script type="text/javascript">
$(function() {
var now = new Date();
var yearsold = new Date();
yearsold.setFullYear((now.getFullYear() - 2));
$('.datepicker').datepicker({
format: 'mm/dd/yyyy',
startDate: yearsold,
endDate: now
});
var defaultDate = moment().format('DD/MM/YYYY');
$("#datePicker1").val(defaultDate);
$("#datePicker2").val(defaultDate);
});
</script>
<div class="col-xs-1">
<label>Start Date:</label>
</div>
<div class='col-sm-3'>
<input class="datepicker form-control" type="text" id="datePicker1" />
</div>
<div class="col-xs-1">
<label>End Date:</label>
</div>
<div class='col-sm-3'>
<input class="datepicker form-control" type="text" id="datePicker2" />
</div>
</div>
<div id="button-pane" class="row">
<div class="col-lg-12">
<!-- <button class="btn btn-primary">Generate Report</button>-->
<input type="submit" id="requestBtn" class="btn btn-primary" value="Generate Report"></input>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
// Validation Function Needed
});
</script>
</form>
<script src="js/bootstrap.js"></script>
</body>
</html>
只啓用如果所有的表單驗證完成
嘗試去爲角, –