javascript - rating is not a function jquery plugin error - Stack Overflow

I have a jsp page. In that i am trying jquery star rating. I am using this plugin . But JS error is in

I have a jsp page. In that i am trying jquery star rating. I am using this plugin /. But JS error is ing like TypeError: $(...).rating is not a function Here is my JSP code.

<div class="book-right" id="ajaxTest">
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.rating.js"></script>
    <script type="text/javascript" src="js/jquery-latest.js"></script>
    <script type="text/javascript" src="js/jquery.tablesorter.js"></script>
    <script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
    <--table + some intermediate loop code --->
        <c:forEach var="leg" items="${option.legs}" varStatus="loopCounter3">
            <div>
                <input type="radio" name="rating-${loopCounter2.index}" value="1" class="rating-star" />
                <input type="radio" name="rating-${loopCounter2.index}" value="2" class="rating-star" />
                <input type="radio" name="rating-${loopCounter2.index}" value="3" class="rating-star" />
                <input type="radio" name="rating-${loopCounter2.index}" value="4" class="rating-star" />
                <input type="radio" name="rating-${loopCounter2.index}" value="5" class="rating-star" />
            </div>
            <input type="hidden" id="avgRating" name="avgRating" value="${leg.courierProduct.rating}"></input>

            <script>
                var avgRating = $('#avgRating').val();
                $('.rating-star').rating('select', avgRating);
            </script>
        </c:forEach>
</div>

I have removed some JSP code to make it simple.

I have a jsp page. In that i am trying jquery star rating. I am using this plugin http://www.fyneworks./jquery/star-rating/. But JS error is ing like TypeError: $(...).rating is not a function Here is my JSP code.

<div class="book-right" id="ajaxTest">
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.rating.js"></script>
    <script type="text/javascript" src="js/jquery-latest.js"></script>
    <script type="text/javascript" src="js/jquery.tablesorter.js"></script>
    <script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
    <--table + some intermediate loop code --->
        <c:forEach var="leg" items="${option.legs}" varStatus="loopCounter3">
            <div>
                <input type="radio" name="rating-${loopCounter2.index}" value="1" class="rating-star" />
                <input type="radio" name="rating-${loopCounter2.index}" value="2" class="rating-star" />
                <input type="radio" name="rating-${loopCounter2.index}" value="3" class="rating-star" />
                <input type="radio" name="rating-${loopCounter2.index}" value="4" class="rating-star" />
                <input type="radio" name="rating-${loopCounter2.index}" value="5" class="rating-star" />
            </div>
            <input type="hidden" id="avgRating" name="avgRating" value="${leg.courierProduct.rating}"></input>

            <script>
                var avgRating = $('#avgRating').val();
                $('.rating-star').rating('select', avgRating);
            </script>
        </c:forEach>
</div>

I have removed some JSP code to make it simple.

Share Improve this question edited Apr 14, 2015 at 6:11 Anoop Joshi P 25.5k9 gold badges35 silver badges54 bronze badges asked Apr 14, 2015 at 6:10 user3681970user3681970 1,2815 gold badges21 silver badges39 bronze badges 1
  • Why are you using jquery.js and jquery-latest.js? Use only one and rating.js should be after jquery file. – anpsmn Commented Apr 14, 2015 at 6:12
Add a ment  | 

1 Answer 1

Reset to default 5

You don't need to load jQuery twice. What happens in this case, is the second time it overwrites previous one with rating prototype method.

This should work for you:

<script src="js/jquery-latest.js"></script>
<script src="js/jquery.rating.js"></script>

Another problem is that you are not initializing plugin properly. It should be:

$('.rating-star').rating().rating('select', avgRating);

... initialize first, then call select method.

Demo: http://plnkr.co/edit/OIjbvkff27YdX4snKnB2?p=preview

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745138282a4613308.html

相关推荐

  • javascript - rating is not a function jquery plugin error - Stack Overflow

    I have a jsp page. In that i am trying jquery star rating. I am using this plugin . But JS error is in

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信