我正在使用 ColorPicker Plugin.我使用以下代码初始化了插件:
$(".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
}
});
现在我的问题是 $(this)
在 onchange
事件中不起作用。请帮帮我好吗?
最佳答案
像这样尝试:
$(".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);
}
});
});
关于javascript - $(this) 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11101759/