我似乎无法弄清楚这里的问题是什么。我已经尝试将我的 js 放在我的脑海中,在我的表单下方,在我的表单上方等等。它们似乎都没有做任何事情。它只是提交页面而不尝试验证
HTML:
<div class="content">
<h1>Submit A Lost Paw</h1>
<p>Please complete the form below. After being reviewed by a moderator, your listing will be posted for others to see.</p>
<ul id="error-box">
</ul>
<form id="test" name="test" action="test.php" method="post">
<div class="section">
<div class="input-title">
<label for="pet_name">Pet Name:</label>
</div>
<div class="input">
<input id="pet_name" type="text" />
</div>
<div class="clear"></div>
</div>
<div class="section">
<div class="input-title">
<label for="date_missing">Date Pet Went Missing:</label>
</div>
<div class="input">
<input id="date_missing" type="text" />
</div>
<div class="clear"></div>
</div>
<div class="section">
<div class="input-title">
<label for="location">Location:</label>
</div>
<div class="input">
<input id="location" type="text" />
</div>
<div class="clear"></div>
</div>
<div class="section">
<div class="input-title">
<label for="age">Age:</label>
</div>
<div class="input">
<input id="age" type="text" />
</div>
<div class="clear"></div>
</div>
<div class="section">
<div class="input-title">
<label for="colors">Colors:</label>
</div>
<div class="input">
<input id="colors" type="text" />
</div>
<div class="clear"></div>
</div>
<div class="section">
<div class="input-title">
<label for="contact_name">Contact Name:</label>
</div>
<div class="input">
<input id="contact_name" type="text" />
</div>
<div class="clear"></div>
</div>
<div class="section">
<div class="input-title">
<label for="phone">Phone:</label>
</div>
<div class="input">
<input id="phone" type="text" />
</div>
<div class="clear"></div>
</div>
<div class="section">
<div class="input-title">
<label for="email">Email:</label>
</div>
<div class="input">
<input id="email" type="text" />
</div>
<div class="clear"></div>
</div>
<div class="section">
<div class="input-title">
<label for="add_details">Additional Details:</label>
</div>
<div class="input">
<textarea id="add_details"></textarea>
</div>
<div class="clear"></div>
</div>
<div class="section">
<div class="input-title">
</div>
<div class="input">
<input type="submit" value="Submit for Review" />
</div>
<div class="clear"></div>
</div>
</form>
</div>
Javascript:
<script type="text/javascript">
$(document).ready(function() {
$("#test").validate({
errorLabelContainer: "#error-box",
wrapper: "li id='error'",
rules: {
pet_name: {
required: true
}
}
});
});
</script>
截至目前,js 直接位于 html 下方,在同一个文件中。整个文件被拉入一个索引页面,该页面的头部拉入了 validate.js 文件。