Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jQuery插件访问$(this)_Javascript_Jquery_Plugins_Selector_This - Fatal编程技术网

Javascript 如何使用jQuery插件访问$(this)

Javascript 如何使用jQuery插件访问$(this),javascript,jquery,plugins,selector,this,Javascript,Jquery,Plugins,Selector,This,我正在使用jqueryrating,在将成功消息显示到相应的div中时遇到问题,因为$(this)不引用选择器,而是返回Object 这是我的密码: $(".basic").jRating({ bigStarsPath: 'assets/stars.png', rateMax: 5, length : 5, phpPath : '<%= Rails.application.class.routes.url_helpers.ratings_pat

我正在使用jqueryrating,在将成功消息显示到相应的div中时遇到问题,因为$(this)不引用选择器,而是返回Object

这是我的密码:

  $(".basic").jRating({
     bigStarsPath: 'assets/stars.png',
     rateMax: 5,
     length : 5,
     phpPath : '<%= Rails.application.class.routes.url_helpers.ratings_path %>',
     onSuccess : function(){
       $(this).find(".message").append('<small>Thanks for your vote!</small>'); 
     }
   });
$(“.basic”).jRating({
bigStarsPath:'assets/stars.png',
最高比率:5,
长度:5,
phpPath:“,
onSuccess:function(){
$(this.find(“.message”).append('谢谢您的投票!');
}
});
所以问题是$(this)没有引用$(“.basic”),我想知道如何访问插件中的选择器。 我很确定这可能是个新问题,但我的javascript技能一点也不全面。
提前谢谢。

成功
的第一个参数是
元素
。用那个

onSuccess : function(element){
  $(element).find(".message").append('<small>Thanks for your vote!</small>'); 
}
onSuccess:函数(元素){
$(元素).find(“.message”).append('谢谢您的投票!');
}
由插件将
this
设置为某物,在这种情况下,插件将
onSuccess
函数与
this
一起触发,作为传递给
jRating
选项,而不是元素。

onSuccess:function(元素,速率){
 onSuccess : function(element, rate){
   $(element).find(".message").append('<small>Thanks for your vote!</small>'); 
 }
$(元素).find(“.message”).append('谢谢您的投票!'); }
您可以在成功选项中访问元素和/或比率。

var elem=$(此选项);
 var elem = $(this);
$(".basic").jRating({
     bigStarsPath: 'assets/stars.png',
     rateMax: 5,
     length : 5,
     phpPath : '<%= Rails.application.class.routes.url_helpers.ratings_path %>',
     onSuccess : function(){
       elem.find(".message").append('<small>Thanks for your vote!</small>'); 
     }
   });
$(“.basic”).jRating({ bigStarsPath:'assets/stars.png', 最高比率:5, 长度:5, phpPath:“, onSuccess:function(){ elem.find(“.message”).append('谢谢您的投票!'); } });
关于jRating源代码,将传递给onSuccess和onError处理程序的参数是元素和评级,因此解决方案是:

$(".basic").jRating({
 bigStarsPath: 'assets/stars.png',
 rateMax: 5,
 length : 5,
 phpPath : '<%= Rails.application.class.routes.url_helpers.ratings_path %>',
 onSuccess : function(element /*, rating */){
   $(element).find(".message").append('<small>Thanks for your vote!</small>'); 
 }
});
$(“.basic”).jRating({
bigStarsPath:'assets/stars.png',
最高比率:5,
长度:5,
phpPath:“,
onSuccess:功能(元素/*,评级*/){
$(元素).find(“.message”).append('谢谢您的投票!');
}
});

对象对象对象是将对象转换为字符串时得到的对象。正在尝试使用
警报($(this))
进行调试?