簡體   English   中英

Yii顏色選擇器更改事件問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM