http://www.myjqueryplugins.com/jRating/demo目前只能选择一次我现在想可以重复选择...如何修改?

解决方案 »

  1.   

    服务器或者cookie控制的。
    多次选择就没有投票的必要了。那种数据还能可信吗
      

  2.   

    老板要求 我们不是采用动态提交的  好像也不属于服务器或者cookie控制!
      

  3.   

    我们添加了一个方法 没用ajax
      

  4.   


    $this.unbind().css('cursor','default').addClass('jDisabled');
    关键似乎是这句 注销掉就可以了 但选区颜色无法变更!
      

  5.   


    jQuery.jRating = {
    build : function(options){
            var defaults = {
    /** String vars **/
    bigStarsPath : 'jrating/icons/stars.png',
    smallStarsPath : 'jrating/icons/small.png',
    type : 'big', // 'small' or 'big'

    /** Boolean vars **/
    step:false,
    isDisabled:false,

    /** Integer vars **/
    length:5,
    decimalLength : 0,
    rateMax : 20,
    rateInfosX : -45,
    rateInfosY : 5,

    onShow : null
            };   

    if(this.length>0)
    return jQuery(this).each(function(i) {
    var opts = $.extend(defaults, options);       
    var $this = $(this);
    var newWidth = 0;
    var starWidth = 0;
    var starHeight = 0;
    var bgPath = '';

    if($this.hasClass('jDisabled') || opts.isDisabled)
    var jDisabled = true;
    else
    var jDisabled = false;

    getStarWidth();
    $this.height(starHeight);

    var average = parseFloat($this.attr('data').split('_')[0]);
    var idBox = parseInt($this.attr('data').split('_')[1]);
    var widthRatingContainer = starWidth*opts.length;
    var widthColor = average/opts.rateMax*widthRatingContainer;


    var $quotient = 
    jQuery('<div>', 
    {
    'class' : 'jRatingColor',
    css:{
    width:widthColor
    }
    }).appendTo($this);

    var $average = 
    jQuery('<div>', 
    {
    'class' : 'jRatingAverage',
    css:{
    width:0,
    top:- starHeight
    }
    }).appendTo($this);

    var $jstar =
    jQuery('<div>', 
    {
    'class' : 'jStar',
    css:{
    width:widthRatingContainer,
    height:starHeight,
    top:- (starHeight*2),
    background: 'url('+bgPath+') repeat-x'
    }
    }).appendTo($this);

    $this.css({width: widthRatingContainer,overflow:'hidden',zIndex:1,position:'relative'});

    if(!jDisabled)
    $this.bind({
    mouseenter : function(e){
    var realOffsetLeft = findRealLeft(this);
    var relativeX = e.pageX - realOffsetLeft;
    var tooltip = 
    jQuery('<p>',{
    'class' : 'jRatingInfos',
    html : getNote(relativeX)+' <span class="maxRate">/ '+opts.rateMax+'</span>',
    css : {
    top: (e.pageY + opts.rateInfosY),
    left: (e.pageX + opts.rateInfosX)
    }
    }).appendTo('body').show();
    },
    mouseover : function(e){
    $this.css('cursor','pointer');
    },
    mouseout : function(){
    $this.css('cursor','default');
    $average.width(0);
    },
    mousemove : function(e){
    var realOffsetLeft = findRealLeft(this);
    var relativeX = e.pageX - realOffsetLeft;
    if(opts.step) newWidth = Math.floor(relativeX/starWidth)*starWidth + starWidth;
    else newWidth = relativeX;
    $average.width(newWidth);
    $("p.jRatingInfos").css({
    left: (e.pageX + opts.rateInfosX)
    })
    .html(getNote(newWidth) +' <span class="maxRate">/ '+opts.rateMax+'</span>');
    },
    mouseleave : function(){
    $("p.jRatingInfos").remove();
    },
    click : function(e){
    $this.unbind().css('cursor','default').addClass('jDisabled');
    $("p.jRatingInfos").fadeOut('fast',function(){$(this).remove();});
    e.preventDefault();
    var rate = getNote(newWidth);
    $average.width(newWidth);
    if(opts.onShow) opts.onShow(rate);
    }
    });

    function getNote(relativeX) {
    var noteBrut = parseFloat((relativeX*100/widthRatingContainer)*opts.rateMax/100);
    switch(opts.decimalLength) {
    case 1 :
    var note = Math.round(noteBrut*10)/10;
    break;
    case 2 :
    var note = Math.round(noteBrut*100)/100;
    break;
    case 3 :
    var note = Math.round(noteBrut*1000)/1000;
    break;
    default :
    var note = Math.round(noteBrut*1)/1;
    }
    return note;
    };

    function getStarWidth(){
    switch(opts.type) {
    case 'small' :
    starWidth = 12;
    starHeight = 10;
    bgPath = opts.smallStarsPath;
    break;
    default :
    starWidth = 23;
    starHeight = 20;
    bgPath = opts.bigStarsPath;
    }
    };

    function findRealLeft(obj) {
      if( !obj ) return 0;
      return obj.offsetLeft + findRealLeft( obj.offsetParent );
    };
    });
    }
    }; jQuery.fn.jRating = jQuery.jRating.build;修改后的代码