2个jquery插件不能以一种形式工作

时间:2011-11-11 20:47:17

标签: jquery

我在表单中有jquery验证和jqtransform,但只有其中一个有效:

    <!-- validation -->
    <script type="text/javascript" src="/sitestatic/scripts/validation/jquery-1.6.min.js"></script>
    <script type="text/javascript" src="/sitestatic/scripts/validation/languages/jquery.validationengine-fr.js" charset="utf-8"></script>
    <script type="text/javascript" src="/sitestatic/scripts/validation/jquery.validationengine.js" charset="utf-8"></script>
    <!-- end validation -->
    <!-- jqtransform -->
    <script type="text/javascript" src="/sitestatic/jqtransformplugin/jquery.js" ></script>
        <script type="text/javascript" src="/sitestatic/jqtransformplugin/jquery.jqtransform.js" ></script>
    <!-- end jqtransform -->
    <script>
<!-- validation script-->
     var $j = jQuery.noConflict();
    $j(document).ready(function(){
                jQuery("#registrationForm").validationEngine();
                $("#id_StatusTypeCode").addClass("validate[required]")
                $("#id_PriceUnitCode").addClass("validate[required]")
                });
    $(function(){

    $("form").form();

    });
<!-- end validation script -->
<!-- jqtransform script-->
    $(function(){
                $('form').jqTransform({imgPath:'jqtransformplugin/img/'});
            });
<!-- end jqtransform script-->
    </script>

但只是jqtransform工作,我该怎么办?

1 个答案:

答案 0 :(得分:2)

删除<script type="text/javascript" src="/sitestatic/jqtransformplugin/jquery.js" ></script>。此导入的Javascript文件将覆盖先前定义的jQuery框架+插件。

会发生什么?

Load jQuery-1.6-min.js   Defines jQuery
Load validation files    Defined jQuery validation plugin
Load jquery.js           Overwrites the previously created jQuery object
                          ^ The jQuery validation plugin is deleted
Load jqtransform         Defined jqtranform plugin

以下代码应该有效:

<!-- jQuery framework -->
<script type="text/javascript" src="/sitestatic/scripts/validation/jquery-1.6.min.js"></script>
<!-- Validaiton -->
<script type="text/javascript" src="/sitestatic/scripts/validation/languages/jquery.validationengine-fr.js" charset="utf-8"></script>
<script type="text/javascript" src="/sitestatic/scripts/validation/jquery.validationengine.js" charset="utf-8"></script>
<!-- end validation -->
<!-- jqtransform -->
    <script type="text/javascript" src="/sitestatic/jqtransformplugin/jquery.jqtransform.js" ></script>
<!-- end jqtransform -->