jQuery验证无法正常工作 [英] jQuery Validate Not Working

查看:71
本文介绍了jQuery验证无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有问题,似乎.validate无法正常工作,但所有文档均已连接并且运行良好:

I have an issue with my code it seems the .validate is not working but all the documents are connected and working sweet:

HTML:

<!DOCTYPE html>
<html>
    <title>Site Name Quote Form</title>
    <link rel="stylesheet" href="http://domain.co.nz/_assets/css/style.css"/>
<body>
    <div id="wrapperQuote">
        <h1>Site Name Quote</h1>

            <p class="quoteError"><?php echo validation_errors(); ?></p>

            <p class="step">Step 1: Company Details</p>

        <form id="quote" action="home/hosting" method="post">
            <fieldset>
            <legend>Company Details:</legend>
            <label for="companyName">Company Name: </label><input type="input" name="companyName" id="companyName"/>
            <label for="companySlogan">Company Slogan: </label><input type="input" name="companySlogan" id="companySlogan"/>
            <label for="companyContact">Company Contact: </label><input type="input" name="companyContact" id="companyContact"/>
            <label for="companyEmail">Company E-Mail: </label><input type="email" name="companyEmail" id="companyEmail"/>
            <label for="companyWebsite">Company Website: </label><input type="url" name="companyWebsite" id="companyWebsite" placeholder="http://"/>
            <label for="companyPhone">Company Phone: </label><input type="phone" name="companyPhone" id="companyPhone"/>
            <label for="companyFax">Company Fax: </label><input type="phone" name="companyFax" id="companyFax"/>
            <label for="companyAddress">Company Address: </label><textarea name="companyAddress" id="companyAddress"></textarea>
            <input type="submit" class="nextButton" value="Next" />
            </fieldset>
        </form>
        </div>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
            <script>window.jQuery || document.write('<script src="http://domain.co.nz/_assets/js/jquery-1.7.2.min.js"><\/script>')</script>
            <script src="http://domain.co.nz/_assets/js/jquery.validate.min.js"></script>
            <script src="http://domain.co.nz/_assets/js/quote.js"></script>
</body>
</html>

quote.js:

jQuery(document).ready(function() { 
    //Home Validation
    $("#quote").validate({
        rules:{
            companyName:{
                required: true,
                url: true
            }
        }
    });
etc etc

推荐答案

您发布的代码正在按预期方式工作...

Your code, as you've posted it, is working as expected... jsFiddle DEMO

关于您的代码...

jQuery(document).ready(function() { 
    //Home Validation
    $("#quote").validate({
        rules:{
            companyName:{
                required: true,
                url: true
            }
        }
    });
});

如果您已将jQuery放入 noConflict模式,则

If you've put jQuery into noConflict mode, then your code in noConflict mode is broken.

在使用noConflict模式时,必须将$符号传递到document.ready函数中. 工作演示 ...

When using noConflict mode, you must pass the $ symbol into the document.ready function. Working demo...

$.noConflict();
jQuery(document).ready(function($) {
    $("#quote").validate({
        // rules
    });
});

或者,您将在任何地方使用jQuery代替$. 工作演示 ...

OR, you'd use jQuery in place of $ everywhere. Working demo...

$.noConflict();
jQuery(document).ready(function() { 
    jQuery("#quote").validate({
        // rules
    });
});

否则,在不使用无冲突模式的情况下,它将看起来像这样. 工作演示 ...

Otherwise, without using no-conflict mode, it would just look like this. Working demo...

$(document).ready(function() {
    $("#quote").validate({
        // rules
    });
});

这篇关于jQuery验证无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆