Getting the value from a jQuery UI Slider

后端 未结 2 1043
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 17:46

I have a jQuery UI slider that is part of a rating system. You slide to values 1 - 5 in order to rate it 1 thru 5. I have it defaulted to 3 when the slider first appears. Th

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-16 18:12

    To display rating as you slide in your slider initialization you need to change the text of that div (Assuming you have a div (not an input box) with an id "ratingResult"). To update the value when user finishes dragging you need to add the change event to the initialization code.

    $("#ratingSlider").slider({
        range: "min",
        value: 3,
        min: 1,
        max: 5,
        //this gets a live reading of the value and prints it on the page
        slide: function(event, ui) {
          $("#ratingResult").text(ui.value);
        },
        //this updates the value of your hidden field when user stops dragging
        change: function(event, ui) {
          $('#rateToPost').attr('value', ui.value);
        }
      });
    

提交回复
热议问题