[英]Yii color picker change event issue
I'm using minicolors color picker for Yii and I want to attach a change event on the color picker input as always: 我正在为Yii使用minicolors颜色选择器,并且希望像往常一样在颜色选择器输入上附加一个change事件:
$('#color_picker').change(function(e) { console.log('It works!') });
But it doesn't work, then I tried: 但这不起作用,然后我尝试了:
$('#color_picker').miniColors({change: function(hex, rgb) { console.log('It works!') }});
This doesn't work either. 这也不起作用。 Considering docs I should attach this event on creation, but why?
考虑到文档,我应该在创建时附加此事件,但是为什么呢? What if I need to attach it after creation, can this be done?
如果我需要在创建后将其附加,该怎么办?
You have been missing the left-right parenthesis {
}
for the supplied options
, here is what is described on official document 您已缺少所提供
options
的左右括号{
}
,这是官方文档中描述的内容
$(selector).minicolors({
change: function(hex, opacity) {
console.log(hex + ' - ' + opacity);
}
});
Edited (1): 编辑(1):
<input id="general_bgColor" type="text">
<script>
$(function(){
$('#general_bgColor').miniColors({ change: function(hex, rgb) { console.log('it worked!'); //console.log(hex + ' - ' + rgb); } });
})
</script>
Edited (2): Here is what you should add using that Yii extension 编辑(2):这是您应该使用该Yii扩展名添加的内容
$this->widget('ext.widgets.SMiniColors.SColorPicker', array(
'id' => 'myInputId',
'defaultValue'=>'#000000',
'hidden'=>false, // defaults to false - can be set to hide the textarea with the hex
'options' => array(
'change' => 'js:function(hex, rgb) { console.log(hex + " - " + rgb); }'
), // jQuery plugin options
'htmlOptions' => array(
), // html attributes
));
Notice my line option 'change'
. 注意我的行选项
'change'
。 I think the single quote on your function string inadvertently make invalid array. 我认为函数字符串上的单引号会无意中使数组无效。 It makes the option key 'change' always has value '0'
它使选项键“ change”始终具有值“ 0”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.