jquery在同一个表单上有多个插件

发布于 2024-09-28 08:29:54 字数 2916 浏览 9 评论 0原文

有人可以看一下这段代码吗?我在表单中使用两个插件。一种用于验证表单字段,另一种用于设置表单字段的样式。

如果我注释掉表单样式代码,表单验证会验证表单。 ( // $('.ul').jqf1(); ) 我希望这两个插件一起工作。

<link href="css/jqf1.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.js"></script>
<script type="text/javascript" src="js/jqf1.english.js"></script>
<script src="js/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $('.ul').jqf1();
$("#priceform").validate({
      rules: {
    email: {
      email: true,
      required: false
    },
    wordcount: {
     required: true,
     number: true
    },
    prating: {
    number: true
    }
  }
});});
</script>


<form action="" method="post" id="priceform">

<ul class="ul">
    <li><label for="Name">Name:</label></li><br/>
    <li><input type="text" id="name" size="20" name="name" maxlength="100" style="width:250px;" /></li>
</ul>

<ul class="ul">
    <li><label for="Email">Email:</label></li><br/>
    <li><input type="text" id="email" size="20" name="email" class="required" maxlength="20" style="width:250px;"/></li>
</ul>

<ul class="ul">
    <li><label for="username">UserName: <span class="optional">(Optional)</span></label></li><br/>
    <li><input type="text" id="username" size="20" name="username" maxlength="20" style="width:250px;"/></li>
</ul>

<ul class="ul">
    <li><label for="wordcount">Paper Word Count:</label><br/><a href="#">Calculate Word Count</a></li>
    <li style="padding-left:12px;"><input type="text" id="wordcount" size="20" name="wordcount" maxlength="20" style="width:50px;"/><span class="cumpolsory">*</span></li>
    <li style="color:green"><label id="totalPrice">$1000</label></li>   
    <li><label style="font-weight: 500; font-size:10px; color: gray;" for="totalprice">(Total Price)</label></li>
</ul>

<ul class="ul">
    <li><label>Plagiarism Rating:</label><br/><a href="#">Free Assessment</a></li>
    <li style="padding-left:15px;"><input type="text" id="prating" size="20" name="prating" maxlength="20" style="width:50px;"/><label>%</label></li>
</ul>

<ul class="ul" style="border-bottom:none;">
    <li><input type="Submit" id="name" size="20" name="name" value="Reset" maxlength="20" style="font-weight:700" /></li>
    <li style="float:right;"><input type="Submit" id="name" size="20" name="name" value="Place Order" maxlength="20" style="font-weight:700" /></li>
</ul>
</form>

Can someone look at this code. I am using two plugins in the form. One to validate form fields and other to style form fields.

Form validation validates form if I am comment out form styling code. ( // $('.ul').jqf1(); )
I want both of the plugins work together.

<link href="css/jqf1.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.js"></script>
<script type="text/javascript" src="js/jqf1.english.js"></script>
<script src="js/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $('.ul').jqf1();
$("#priceform").validate({
      rules: {
    email: {
      email: true,
      required: false
    },
    wordcount: {
     required: true,
     number: true
    },
    prating: {
    number: true
    }
  }
});});
</script>


<form action="" method="post" id="priceform">

<ul class="ul">
    <li><label for="Name">Name:</label></li><br/>
    <li><input type="text" id="name" size="20" name="name" maxlength="100" style="width:250px;" /></li>
</ul>

<ul class="ul">
    <li><label for="Email">Email:</label></li><br/>
    <li><input type="text" id="email" size="20" name="email" class="required" maxlength="20" style="width:250px;"/></li>
</ul>

<ul class="ul">
    <li><label for="username">UserName: <span class="optional">(Optional)</span></label></li><br/>
    <li><input type="text" id="username" size="20" name="username" maxlength="20" style="width:250px;"/></li>
</ul>

<ul class="ul">
    <li><label for="wordcount">Paper Word Count:</label><br/><a href="#">Calculate Word Count</a></li>
    <li style="padding-left:12px;"><input type="text" id="wordcount" size="20" name="wordcount" maxlength="20" style="width:50px;"/><span class="cumpolsory">*</span></li>
    <li style="color:green"><label id="totalPrice">$1000</label></li>   
    <li><label style="font-weight: 500; font-size:10px; color: gray;" for="totalprice">(Total Price)</label></li>
</ul>

<ul class="ul">
    <li><label>Plagiarism Rating:</label><br/><a href="#">Free Assessment</a></li>
    <li style="padding-left:15px;"><input type="text" id="prating" size="20" name="prating" maxlength="20" style="width:50px;"/><label>%</label></li>
</ul>

<ul class="ul" style="border-bottom:none;">
    <li><input type="Submit" id="name" size="20" name="name" value="Reset" maxlength="20" style="font-weight:700" /></li>
    <li style="float:right;"><input type="Submit" id="name" size="20" name="name" value="Place Order" maxlength="20" style="font-weight:700" /></li>
</ul>
</form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

榆西 2024-10-05 08:29:54

此 URL (http://www.webreference.com/programming/javascript/jquery/form_validation/) 是您的参考。

您可以尝试将其放入页面中,看看它的响应如何。

<样式类型=“text/css”>
#priceform label.error { 宽度:250px;显示:块;浮动:向左;颜色: 红色;左内边距:10px; }
< /风格>

This URL (http://www.webreference.com/programming/javascript/jquery/form_validation/) is the reference for you.

You can try to put this one to see how it responds in the page.

< style type="text/css">
#priceform label.error { width: 250px; display: block; float: left; color: red; padding-left: 10px; }
< /style>

如此安好 2024-10-05 08:29:54

您是否在 css 文件中添加了“label.error”css 代码来显示错误代码?

Did you add "label.error" css code in your css file to show the error code?

女中豪杰 2024-10-05 08:29:54

尝试:
1.将样式调用移至验证之后。

或者

  1. 强制执行某些操作,例如在样式设置后发出警报,以确保脚本在验证分配发生之前不会悄然消失。

try:
1. move the styling call to after the validation.

or

  1. force some action such as an alert after the styling to make sure that script didn't bomb out quietly before the validation assignment takes place.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文