1

在我的网站中使用时,我遇到了两个相互冲突的 jquery 库的问题。我的标题部分中有以下内容:

<link rel="stylesheet" type="text/css" href="http://megaworldlifestylemalls.com/admin/static/css/rating.css">
<script src="http://megaworldlifestylemalls.com/admin/static/js/jquery.js"></script>
<script src="http://megaworldlifestylemalls.com/admin/static/js/rating.js"></script>
<script type="text/javascript">
             var Rating = jQuery.noConflict(true);
</script>

<script src="http://megaworldlifestylemalls.com/admin/static/js/less.js" type="text/javascript"></script>

<link rel="stylesheet" media="handheld" href="http://megaworldlifestylemalls.com/admin/static/css/handheld.css?v=2">
<script src="http://megaworldlifestylemalls.com/admin/static/js/libs/modernizr-1.7.min.js"></script>
<script src="http://megaworldlifestylemalls.com/admin/static/js/libs/respond.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.5.1.min.js"%3E%3C/script%3E'))</script>
<script src="http://megaworldlifestylemalls.com/admin/static/js/plugins.js"></script>
<script src="http://megaworldlifestylemalls.com/admin/static/js/script.js"></script>

我在循环中的页面正文中有以下代码:

            <td>
                <div class="rating" id="rating818" data-rate="0"></div>
                <script type="text/javascript">
                        $(document).ready(function(){
                              Rating('#rating818').rating({maxvalue:5, curvalue: 0, image:'http://megaworldlifestylemalls.com/admin/static/img/star.gif'});
                        });
                </script>
            </td>

但它显示以下错误:

Uncaught TypeError: Object function jQuery(a,c) {

    // Shortcut for document ready (because $(document).each() is silly)
    if ( a && a.constructor == Function && jQuery.fn.ready )
        return jQuery(document).ready(a);

    // Make sure that a selection was provided
    a = a || jQuery.context || document;

    // Watch for when a jQuery object is passed as the selector
    if ( a.jquery )
        return jQuery( jQuery.merge( a, [] ) );

    // Watch for when a jQuery object is passed at the context
    if ( c && c.jquery )
        return jQuery( c ).find(a);

    // If the context is global, return a new object
    if ( window == this )
        return new jQuery(a,c);

    // Handle HTML strings
    var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
    if ( m ) a = jQuery.clean( [ m[1] ] );

    // Watch for when an array is passed in
    this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
        // Assume that it is an array of DOM Elements
        jQuery.merge( a, [] ) :

        // Find the matching elements and save them for later
        jQuery.find( a, c ) );

  // See if an extra function was provided
    var fn = arguments[ arguments.length - 1 ];

    // If so, execute it in context
    if ( fn && fn.constructor == Function )
        this.each(fn);
} has no method 'noConflict' 1:25
(anonymous function) 1:25
Uncaught TypeError: Property 'Rating' of object [object Object] is not a function 1:126
(anonymous function) 1:126
f.resolveWith jquery.min.js:16
d.extend.ready jquery.min.js:16
c.addEventListener.A jquery.min.js:16

我的评级库代码是:

jQuery.fn.rating = function(options) {

    var settings = {
        maxvalue  : 5,   // max number of stars
        curvalue  : 0,    // number of selected stars
        image     : ''
    };

    if(options) {
       jQuery.extend(settings, options);
    };

    var container = jQuery(this);

    jQuery.extend(container, {
            averageRating: settings.curvalue
        });

    for(var i= 0; i <= settings.maxvalue ; i++){
        var size = i;
                if(i==0) continue;
                var div = '<div class="star"><a href="#'+i+'" title="Give it '+i+'/'+size+'">'+i+'</a></div>';
                container.append(div);
    }


        var stars = jQuery(container).find('.star');

    var event = {
        fill: function(el){ // fill to the current mouse position.
            var index = stars.index(el) + 1;
            stars
                .find('a').css('width', '100%').end()
                .lt(index).addClass('hover').end();
        },
        drain: function() { // drain all the stars.
            stars
                .filter('.on').removeClass('on').end()
                .filter('.hover').removeClass('hover').end();
        },
        reset: function(){ // Reset the stars to the default index.
            stars.lt(settings.curvalue).addClass('on').end();
        }
    }
    event.reset();

    return(this);

}
4

1 回答 1

0

尝试这个:

 <link rel="stylesheet" type="text/css" href="http://megaworldlifestylemalls.com/admin/static/css/rating.css">
<script src="http://megaworldlifestylemalls.com/admin/static/js/jquery.js"></script>
<script src="http://megaworldlifestylemalls.com/admin/static/js/rating.js"></script>
<script type="text/javascript">
             jQuery.noConflict();
</script>

然后...

$(document).ready(function(){
                              jQuery('#rating818').rating({maxvalue:5, curvalue: 0, image:'http://megaworldlifestylemalls.com/admin/static/img/star.gif'});
                        });
于 2013-05-28T02:57:51.990 回答