0

我在一个新网站上构建了一个表单,并正在寻找一些使用 JQuery 进行表单验证的帮助,但不知道从哪里开始。我已经下载了http://plugins.jquery.com/validationengine/。在 head 标记中引用了 JQuery 库和验证器引擎。我现在不太确定如何让引擎与我的表单一起工作。下面是我的代码:

<div id="form">

    <form method="post" action="mailto:" enctype="text/plain">
    <INPUT TYPE="HIDDEN" NAME="RECIPIENT" VALUE="">
    <INPUT TYPE="HIDDEN" NAME="SUBJECT" VALUE="enquiry">

      <div id="col1">
                <label>First Name</label><br />
                <input id="fname" name="first name" class="input" type="text" value=""/>
                <div id="clear"></div>

                <label>Surname</label><br />
                <input id="sname" name="Surname" class="input" type="text" value="" />
                <div id="clear"></div>

                <label>Telephone Number</label><br />
                <input id="tel" name="telephone" class="input" type="text" value="" />
                <div id="clear"></div>

                <label>E mail</label><br />
                <input id="email" name="email" class="input" type="text" value="" />
                <div id="clear"></div>

                <label>Message Subject</label><br />
                <select size="1" name="subject" id="subject">
                  <option>Please choose:</option>
                  <option>Beauty Treatments</option>
                  <option>Holistic & Massage Treatments</option>
                  <option>Pamper Parties / Events</option>
                  <option>After Care</option>
                  <option>Special Offers</option>
                  <option>Other</option>
                </select>
                <div id="clear"></div>
                </div>

                <div id="col2">                    
                <label>Message</label><br />
                <textarea id="message" name="notes" cols="" rows="" class="textarea"></textarea>

      </div>

我是 JQuery 的新手,需要先了解基本知识。

谢谢

史蒂夫

4

1 回答 1

1

Follow this:

Download jquery validation engine plugin from here. And extract it.

Inside the folder you can find these two files.

jquery.validationEngine-en.js 
jquery.validationEngine.js

Copy & Paste in assets->scripts-> of your working project.

Then change the src path like below.

<script src="assets/scripts/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>

<script src="assets/scripts/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>

In Your Coding do the following:

<script>
    $(document).ready(function(){
        $("#id of ur form").validationEngine();
    });
</script>


<label>First Name</label><br />
 <input id="fname" name="first name" class="validate[required,minSize[6],maxSize[10]]" type="text" value=""/>


 <label>Surname</label><br />
 <input id="sname" name="Surname" class="validate[required,minSize[6],maxSize[10]]" type="text" value="" />


 <label>Telephone Number</label><br />
 <input id="tel" name="telephone" class="validate[required,custom[onlyNumberSp],maxSize[10]]" type="text" value="" />


 <label>E mail</label><br />
 <input id="email" name="email" class="validate[required,custom[email],maxSize[30]]" type="text" value="" />
于 2013-07-06T10:27:50.517 回答