[英]Yii color picker change event issue
我正在为Yii使用minicolors颜色选择器,并且希望像往常一样在颜色选择器输入上附加一个change事件:
$('#color_picker').change(function(e) { console.log('It works!') });
但这不起作用,然后我尝试了:
$('#color_picker').miniColors({change: function(hex, rgb) { console.log('It works!') }});
这也不起作用。 考虑到文档,我应该在创建时附加此事件,但是为什么呢? 如果我需要在创建后将其附加,该怎么办?
您已缺少所提供options
的左右括号{
}
,这是官方文档中描述的内容
$(selector).minicolors({
change: function(hex, opacity) {
console.log(hex + ' - ' + opacity);
}
});
编辑(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>
编辑(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
));
注意我的行选项'change'
。 我认为函数字符串上的单引号会无意中使数组无效。 它使选项键“ change”始终具有值“ 0”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.