如何重置星级评分的rateYo插件?

时间:2017-04-17 18:50:44

标签: javascript jquery bootstrap-modal rateyo

我在我的项目中使用rateYo插件进行星级评分。提交我的使用星级评级插件的boostrap模式后,我想重置我的表单值以及要重置的星号。基本上我想在用户关闭模态时重置星级评分插件 下面是我的代码JS代码,用于初始化rateYo插件并在模态解除后重置表单值。

        $(function () {

var rateYo = $("#rateYo").rateYo({
    fullStar: true,
    onSet: function (rating, rateYoInstance) {
       rating = Math.ceil(rating);
       $('#rating_input').val(rating);//setting up rating value to hidden field
    }
  });
});

    $('#saveFeedbackBtn').click(function(e){
    e.preventDefault();

var name = $("#name_txt_modal").val();
var rating = $("#rating_input").val();
var topic = $("#topic_sel_modal").val();
var comments = $("#comment_txt_modal").val();
if(name == "") {
  $('#feedbackmodalerrortext').html("Please enter your Name");
    e.preventDefault();
    return false;
  } else if(rating == "") {
      $('#feedbackmodalerrortext').html("Please select a rating");
    e.preventDefault();
    return false;
  }  else if(topic == "select") {
      $('#feedbackmodalerrortext').html("Please select a topic");
        e.preventDefault();
        return false;
      }
  else if(comments == "") {
      $('#feedbackmodalerrortext').html("Please enter comments");
      e.preventDefault();
      return false;
      }
       $('#messageFB').append('');
       $('#feedbackmodalerrortext').html("");
  $.ajax({
        url : "feedbackData.htm?name="+name+"&ratingId="+rating+"&topicId="+topic+"&comment="+comments,
        type: "POST",
        async : false,
        data : "html",
        beforeSend:function(){
            $('#messageFB').html('');
        },
        success: function(response) {
            console.debug(response);
            if (response == "success") {
                $('#messageFB').html('Feedback Saved successfully!');
                $('#messageFB').show();

                setTimeout(function () {
                    $('#messageFB').fadeOut(function(){
                        $('#messageFB').hide();
                    });
                }, 1000);

            } else {
                $('#messageFB').html('Error Saving Feedback data!');
                $('#messageFB').show();

                setTimeout(function () {
                    $('#messageFB').fadeOut(function(){
                        $('#messageFB').hide();
                    });
                }, 1000);
            }

        }     

  });
 });


   $('#myfeedbackModal').on('hidden.bs.modal', function (e) {
   $rateYo.rateYo("option", "rating", 0);  /resetting star rating plugin
  $(this)
    .find("input,textarea,select,span")
       .val('')
       .end()
    .find("input[type=checkbox], input[type=radio]")
       .prop("checked", "")
       .end()
   .find("#rateYo").val('')
  .end()
  .find("feedbackmodalerrortext").val('')
  .end();

    })

2 个答案:

答案 0 :(得分:3)

您可以使用$("#rateYo").rateYo("option", "rating", "0");

您可以在官方链接here

上找到详细信息选项

答案 1 :(得分:2)

您可以将评级设置为0,以便技术上“重置”。根据{{​​3}},您可以执行以下操作:

$("#rateYo").rateYo("rating", 0);
相关问题