Jquery plugins 光谱颜色选择器无法返回“;背景色:透明;

Jquery plugins 光谱颜色选择器无法返回“;背景色:透明;,jquery-plugins,color-picker,spectrum,Jquery Plugins,Color Picker,Spectrum,我正在创建一个简单的HTML编辑器,用户可以在其中编辑预先制作的HTML块 其中一个块有一个默认的背景色,我正在使用Spectrum给用户改变它的机会 因为已经有一个默认背景(由css提供),所以当选择空时,我需要spectrum返回“background color:transparent”,所以默认值将被覆盖,但是spectrum返回的是一个空字符串(?) 有没有返回“背景色:透明”的方法 这是我当前的设置: $('input[data-toggle="colorpicker"]').spe

我正在创建一个简单的HTML编辑器,用户可以在其中编辑预先制作的HTML块

其中一个块有一个默认的背景色,我正在使用Spectrum给用户改变它的机会

因为已经有一个默认背景(由css提供),所以当选择空时,我需要spectrum返回“background color:transparent”,所以默认值将被覆盖,但是spectrum返回的是一个空字符串(?)

有没有返回“背景色:透明”的方法

这是我当前的设置:

$('input[data-toggle="colorpicker"]').spectrum({

    showInput: true,
    allowEmpty: true,
    showButtons: true,
    clickoutFiresChange: true,
    preferredFormat: "name"

});

尝试使用更改事件

$('input[data-toggle="colorpicker"]').spectrum({
    showInput: true,
    allowEmpty: true,
    showButtons: true,
    clickoutFiresChange: true,
    preferredFormat: "name",
    change: function(color) {
       if(color==''){
         // do something here
       }
   }
}); 

尝试使用更改事件

$('input[data-toggle="colorpicker"]').spectrum({
    showInput: true,
    allowEmpty: true,
    showButtons: true,
    clickoutFiresChange: true,
    preferredFormat: "name",
    change: function(color) {
       if(color==''){
         // do something here
       }
   }
}); 
这是我的解决方案:

$(".colorpicker").spectrum({
    showInput: true, 
    showPalette: true, 
    preferredFormat: "hex6",
    showButtons: false,
    clickoutFiresChange: true,
    palette: [["transparent"]],
    change: function(color) {
        if(color.alpha===0) 
            color = "transparent";
        else color = color.toHexString();
        $(this).val(color);
    }
});
这是我的解决方案:

$(".colorpicker").spectrum({
    showInput: true, 
    showPalette: true, 
    preferredFormat: "hex6",
    showButtons: false,
    clickoutFiresChange: true,
    palette: [["transparent"]],
    change: function(color) {
        if(color.alpha===0) 
            color = "transparent";
        else color = color.toHexString();
        $(this).val(color);
    }
});
这是我的解决方案,用于检查所选颜色是否透明。由于无法将透明值转换为hexstring,因此需要手动检查透明为string

这是我的解决方案,用于检查所选颜色是否透明。由于无法将透明值转换为hexstring,因此需要手动检查透明为string