我尝试使用 jQuery 验证器,但它似乎只是没有响应。我正在尝试验证图像上传表单是否不为空。我添加了该if(jQuery)
部分以检查是否实际包含 jQuery,并且确实包含。我无法弄清楚是什么导致了它发生。任何建议都会有所帮助。
HTML 代码:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="bootstrap/js/jquery.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="sys/jsFunc.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
<meta charset="utf-8">
<title>picLoc</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="../assets/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<!-- Main hero unit for a primary marketing message or call to action -->
<div class="hero-unit">
<center>
<h2>Upload a picture and find where exactly it was taken</h2>
</br>
<h2>It really works !</h2>
</br>
<form action="results.php" id="upload-image" method="post" enctype="multipart/form-data">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-preview thumbnail" style="width: 200px; height: 150px;"></div>
<div>
<span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span><input type="file" name="pic" id="pic"/></span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
<button type="submit" class="btn">Upload</button>
</div>
</form>
</center>
</div>
<hr>
<footer></footer>
</div> <!-- /container -->
</body>
</html>
JavaScript 代码:
if(jQuery)
{
alert('included');
}
else
{
alert('not included');
}
jQuery.validator.setDefaults(
{
debug: true,
success: "valid"
});
$(document).ready(function()
{
$('#upload-image').validate(
{
rules :
{
pic :
{
required : true,
accept : "image/*"
}
}
});
});