gpt4 book ai didi

javascript - jQuery 验证插件无法正常工作

转载 作者:行者123 更新时间:2023-11-30 07:26:17 26 4
gpt4 key购买 nike

我似乎无法弄清楚这里的问题是什么。我已经尝试将我的 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 文件被拉入头部。

最佳答案

您需要在输入字段上使用名称属性,例如

<input id="pet_name" name="pet_name" type="text" />

关于javascript - jQuery 验证插件无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13994101/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com