1

我有一个函数可以平均来自多个滑块的所有值。我正在尝试从该平均值中获取数据并插入到推文中。示例:“我刚刚在玩这个很棒的游戏时得了100分!” 点值显然是根据平均值动态变化的。我对 Javascript/Jquery 非常陌生,因此请在回答时包含大量详细信息。谢谢!这是我的 jQuery:

  $(function readTweet() {
    $(document).ready(function () {
      console.log($(".tweet").text());
    });


  $(function(average) {

        var numberOfRatings = $(".rating").length,
        average;

        $( ".slider" ).slider().find(".ui-slider-handle").addClass("custom");

    $( ".slider" ).slider({
      range: "min",
      value: 5,
      min: 1,
      max: 10,
      slide: function( event, ui ) {
        var total = 0;

        $(this).siblings( ".rating" ).text(ui.value);

        $(".rating").each(function () {
          var ratingValue = parseInt($(this).text(), 10);  
          total = parseFloat(total + ratingValue);
          console.log(ratingValue);
        });
        average =(total/numberOfRatings).toFixed(2);


        $("#average").text(average);
            $(".tweet").click(function (){
              $(this).html("I just scored " + average + "points playing this awesome game!");
            });

      }
    });
    $( ".rating" ).text($( ".slider" ).slider( "value" ) );

      $(".ui-slider-handle").focus(function() {
        $(this).removeClass("ui-state-hover ui-state-default ui-state-focus ui-state-active");
      });
  });    


    });

HTML:

    <div id="grand-total">
      <h1>Album Rating</h1>
      <h2 type="text" id="average" value="0">0</h2>
   <a href="https://twitter.com/intent/tweet?" class="twitter-mention-button tweet">Tweet to </a>
  <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>   
4

0 回答 0