0

我正在尝试复制我们代码中其他地方使用的评级插件,但它失败了。可能是我将 js 和 css 包含在错误的顺序中。除非我将课程更改为 STAR,否则星星也不会出现。因为它是我只是得到单选按钮。该事件永远不会触发。在开发工具中比较两个页面(新页面和有效页面)时,一切似乎都是一样的。

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>     
    <link href='/assets/css/jquery.rating.css' type="text/css" rel="stylesheet"/>
    <script src='/assets/js/jquery.MetaData.js' type="text/javascript" language="javascript"></script>
    <script src='/assets/js/jquery.rating.pack.js' type="text/javascript" language="javascript"></script>
</head>

<script>
$(function(){
 $('.auto-submit-star').rating({
 **Uncaught type error: Object[object Object] has no method 'rating'**
  callback: function(value, link){
    // 'this' is the hidden form element holding the current value
            // 'value' is the value selected
            // 'element' points to the link element that received the click.
            alert("The value selected was '" + value + "'\n\nWith this callback function I can automatically submit the form with this code:\nthis.form.submit();");

            // To submit the form automatically:
            //this.form.submit();

            // To submit the form via ajax:
            //$(this.form).ajaxSubmit();
            $.ajax({
                url: '/services/Mentor.cfc',
                data: {
                    method: 'insertRating',
                    rating: value
                },
                //success: function(data){
                //  if (data == true) {
                //      alert('true!');
                //  }
                //  else {
                //      alert('false!');
                //  }
                //}
            });
        }
 });
});
</script>

<cfif qRating.recordCount GT 0>
            <input name="rating_#request.target_id#" type="radio" class="star required" value="#request.target_id#_1"<cfif qRating.rating EQ 1> checked="checked" disabled="disabled"</cfif> />
            <input name="rating_#request.target_id#" type="radio" class="star" value="#request.target_id#_2"<cfif qRating.rating EQ 2> checked="checked" disabled="disabled"</cfif> />
            <input name="rating_#request.target_id#" type="radio" class="star" value="#request.target_id#_3"<cfif qRating.rating EQ 3> checked="checked" disabled="disabled"</cfif> />
            <input name="rating_#request.target_id#" type="radio" class="star" value="#request.target_id#_4"<cfif qRating.rating EQ 4> checked="checked" disabled="disabled"</cfif> />
            <input name="rating_#request.target_id#" type="radio" class="star" value="#request.target_id#_5"<cfif qRating.rating EQ 5> checked="checked" disabled="disabled"</cfif> />
        <cfelse>
            <input name="rating_#request.target_id#" type="radio" class="auto-submit-star star required" value="#request.target_id#_1" />
            <input name="rating_#request.target_id#" type="radio" class="auto-submit-star star" value="#request.target_id#_2" />
            <input name="rating_#request.target_id#" type="radio" class="auto-submit-star star" value="#request.target_id#_3" />
            <input name="rating_#request.target_id#" type="radio" class="auto-submit-star star" value="#request.target_id#_4" />
            <input name="rating_#request.target_id#" type="radio" class="auto-submit-star star" value="#request.target_id#_5" />
        </cfif>
4

1 回答 1

1

查看您粘贴的脚本,您有一些问题。

  1. 以下行没有被正确注释掉,**Uncaught type error: Object[object Object] has no method 'rating'** 这行在您的代码中做了什么?它似乎是您作为评论插入的某种形式的异常,但您的评论语法不正确。完全删除它,或者如果您必须保留它,请将其更改为这个,/**Uncaught type error: Object[object Object] has no method 'rating'**/

  2. 下一个问题是您注释掉了 $ajax 对象的“Success”成员方法,但在其上方保留了逗号。这将仅针对语法引发异常。

编辑:我上面列表中的第 2 位实际上是不准确的。JS 确实允许在对象字面量成员集合中使用尾随逗号。

于 2013-09-19T11:59:24.190 回答