【发布时间】:2015-12-08 03:12:56
【问题描述】:
我正在使用Spectrum 作为颜色选择器的 jquery 插件,以便在 contenteditable div 中使用它。在 chrome 和 firefox 中,它工作得很好。但在 Internet Explorer 中,它只是显示调色板,但当我选择时,什么都没有改变。
但是,如果我以这种方式直接执行execCommand,它就可以工作:
$('#btn-color_font').click(function() {
document.execCommand('foreColor', false, "#ff0000");
});
我做错了什么?请帮助我如何在 IE 中使用它。谢谢。
sn-p html:
<li class="main-btn">
<a href="#" id="btn-color_font" class="wysiwyg-color-spectrum-cF">cF</a>
</li>
<li class="main-btn" >
<a href="#" id="btn-color_background" class="wysiwyg-color-spectrum-bF">cB</a>
</li>
sn-p js:
$(".wysiwyg-color-spectrum-cF").spectrum({
showPaletteOnly: true,
togglePaletteOnly: true,
togglePaletteMoreText: 'more',
togglePaletteLessText: 'less',
color: 'blanchedalmond',
change: function (color) {
document.execCommand('foreColor', false, color.toHexString());
},
hideAfterPaletteSelect: true,
palette: [
["#000", "#444", "#666", "#999", "#ccc", "#eee", "#f3f3f3", "#fff"],
["#f00", "#f90", "#ff0", "#0f0", "#0ff", "#00f", "#90f", "#f0f"],
["#f4cccc", "#fce5cd", "#fff2cc", "#d9ead3", "#d0e0e3", "#cfe2f3", "#d9d2e9", "#ead1dc"],
["#ea9999", "#f9cb9c", "#ffe599", "#b6d7a8", "#a2c4c9", "#9fc5e8", "#b4a7d6", "#d5a6bd"],
["#e06666", "#f6b26b", "#ffd966", "#93c47d", "#76a5af", "#6fa8dc", "#8e7cc3", "#c27ba0"],
["#c00", "#e69138", "#f1c232", "#6aa84f", "#45818e", "#3d85c6", "#674ea7", "#a64d79"],
["#900", "#b45f06", "#bf9000", "#38761d", "#134f5c", "#0b5394", "#351c75", "#741b47"],
["#600", "#783f04", "#7f6000", "#274e13", "#0c343d", "#073763", "#20124d", "#4c1130"]
]
});
【问题讨论】:
-
为什么不使用这个:ajaxtoolkit.net/ColorPicker/ColorPicker.aspx???
-
有趣的问题...只要在 IE 中点击一个颜色,文本选择就会消失——因此没有文本可以再更改了。请检查:stackoverflow.com/questions/12778508/…
-
@ÁlvaroG.Vicario 好的,我会调查的。谢谢。
-
@Stranger 很抱歉,但我认为这是一个完全不同的背景。
-
@Karl 我知道这是不同的,但只是作为一个使用简单的颜色选择器没有任何困难的建议。
标签: javascript jquery internet-explorer contenteditable