我正在尝试复制代码中其他地方使用的评级插件,但它失败了。可能是我以错误的顺序包含了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>
答案 0 :(得分:1)
查看您粘贴的脚本,您有一些问题。
以下行没有被注释掉,**Uncaught type error: Object[object Object] has no method 'rating'**
这行在您的代码中做了什么?它似乎是您作为评论插入的某种形式的例外,但您的评论语法并不正确。完全删除它,或者如果必须保留它,请将其更改为此,/**Uncaught type error: Object[object Object] has no method 'rating'**/
下一个问题是,您已经评论了“成功”和“成功”。 $ ajax对象的成员方法,但将逗号留在其上方。这将仅为语法抛出异常。
编辑:我上面列表中的第2个实际上是不准确的。 JS确实允许在对象文字成员集合中使用尾随逗号。