【鋒利的jQuery】表單驗證外掛程式踩坑

來源:互聯網
上載者:User

標籤:strong   電子   自己   sub   type   姓名   function   下載   讀取   

和前幾篇博文提到的一樣,由於版本原因,【鋒利的jQuery】表單驗證外掛程式部分又出現照著敲不出效果的情況。

  • 書中的使用方法:

    1. 引入jquery源檔案,

           2. 引入表單驗證外掛程式js檔案,

           3. 在form中class類名中添加"required","email"等去作為驗證時讀取的參數。

           4. 調用代碼: $("#commentform").validate();

  很不幸,報錯了。前端有個說法是學新不學舊,這裡就不去深究原因,直接提供最新的寫法。

  • 最新寫法:

    1. 開啟 http://code.ciaoca.com/jquery/validation-engine/  下載

      step one:

      

      step two:

      

       step three: 

          框選的兩個檔案是我們需要用到的,其中languages裡面存放的是各語言的設定檔。

 

           2. 引入jquery源檔案,

     3. 引入表單驗證外掛程式設定檔,

           4. 引入表單驗證外掛程式 (檔案引入如:)

      

 

           5. 驗證設定,直接在class類名中加入即可。以下是按書中原本驗證需求用最新方法改寫的html結構:

    <form method="get" action="#" class="cmxform" id="commentform">        <fieldset>            <legend>一個簡單的驗證帶驗證提示的例子</legend>            <p>                <label for="cusername">姓名</label><em>*</em>                <input type="text" id="cusername" name="username" size="25" class="validate[required,minSize[2],maxSize[11]]">            </p>            <p>                <label for="cemail">電子郵件</label><em>*</em>                <input type="text" id="cemail" name="email" size="25" class="validate[required,custom[email]]">            </p>            <p>                <label for="curl">網址</label><em>*</em>                <input type="text" id="curl" name="url" size="25" class="validate[required,custom[url]]">            </p>            <p>                <label for="ccomment">你的評論</label><em>*</em>                <textarea type="text" id="ccomment" name="comment" size="22" class="validate[required]"></textarea>            </p>            <p>                <input type="submit" class="submit" value="提交">            </p>        </fieldset>    </form> 

    6. 調用代碼: 

<script>    $(function(){        $("#commentform").validationEngine();    })</script>

 

另外,設定驗證還可以自訂參數,並且支援鏈式操作。感興趣的可以自己研究 -- > http://code.ciaoca.com/jquery/validation-engine/

 

【鋒利的jQuery】表單驗證外掛程式踩坑

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.