[英]$(this) is not working
I am using ColorPicker Plugin. 我正在使用ColorPicker插件。 I initialized the plugin with following code :
我使用以下代码初始化了插件:
$(".colorpic").ColorPicker({
color: '#0000ff',
onShow: function (colpkr) {
$(colpkr).fadeIn(500);
return false;
},
onHide: function (colpkr) {
$(colpkr).fadeOut(500);
return false;
},
onChange: function (hsb, hex, rgb) {
$(this).css('backgroundColor', '#' + hex); <= $(this) not working
}
});
Now my problem is that $(this)
is not working in onchange
event. 现在我的问题是
$(this)
无法在onchange
事件中工作。 Help me out please? 请帮帮我
Try like this: 试试这样:
$(".colorpic").each(function(){
var $this = $(this);
$this.ColorPicker({
color: '#0000ff',
onShow: function (colpkr) {
$(colpkr).fadeIn(500);
return false;
},
onHide: function (colpkr) {
$(colpkr).fadeOut(500);
return false;
},
onChange: function (hsb, hex, rgb) {
$this.css('backgroundColor', '#' + hex);
}
});
});
The this
is a really big problem, since in this case the this
goes to the function if I am not mistaken. this
是一个非常大的问题,因为在这种情况下,如果我没有弄错的话, this
将涉及到这个功能。 Try the following: 请尝试以下方法:
var colorPicker=this;
onChange: function (hsb, hex, rgb) {
$(colorPicker).css('backgroundColor', '#' + hex);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.