0

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

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>

引用.js:

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

1 回答 1

7

正如您发布的那样,您的代码正在按预期工作...... jsFiddle DEMO

关于你的代码...

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

如果您已将 jQuery 置于noConflict 模式,那么您在 noConflict 模式下的代码将被破坏

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

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

或者,你会jQuery在任何地方使用$工作演示...

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

否则,如果不使用无冲突模式,它将看起来像这样。 工作演示...

$(document).ready(function() {
    $("#quote").validate({
        // rules
    });
});
于 2012-04-12T22:45:26.057 回答