使用Java脚本删除HTML中的背景色和字体颜色 [英] Remove background color and font color in HTML with Javascript
问题描述
我正在改进TinyMCE编辑器,并希望在原色和背景色中添加按钮默认颜色.这是我如何获得具有随机背景颜色样式的选定文本的方法:
I am improving TinyMCE editor and want to add buttons Default color in forecolor and backcolor. This is how I get selected text with random style of background colors:
outer = tinyMCE.activeEditor.selection.getNode().outerHTML;
例如,可能会有类似的内容:
For example, there could be something like this:
<p style="font-size: 18px;">
sadasdasdsasdasda
<span style="background-color: rgb(0, 255, 0);" data-mce-style="background-color: #00ff00;">sdasdasda</span>
<span style="background-color: rgb(255, 0, 0);" data-mce-style="background-color: #ff0000;">
<span style="background-color: rgb(0, 255, 0);">sdasd</span>
asdasdasdas
</span>
dasdasd
</p>
我已经在jQuery中尝试过.each
,但是没有用.这是实际的代码:
I already tried .each
in jQuery, but not worked. This is that actual code:
$(outer).each(function() {
$(this).css({'background-color': 'transparent'});
});
我不是Java的高手,也不是jQuery的高手.我该怎么做才能从outer
中删除所有background-color
?
I am not master in Javascript, neither in jQuery. What could I do to remove all background-color
from outer
?
推荐答案
所需要的只是插件(plugins/textcolor/plugin.js
)中的编辑功能.那么结果将是:
All to need is edit function in plugin (plugins/textcolor/plugin.js
). Then result will be:
function onPanelClick(e) {
var buttonCtrl = this.parent(), value;
if ((value = e.target.getAttribute('data-mce-color'))) {
buttonCtrl.hidePanel();
buttonCtrl.color(value););
if (value == 'transparent') {
tinyMCE.execCommand("RemoveFormat");
} else {
editor.execCommand(buttonCtrl.settings.selectcmd, false, value);
}
}
}
在那之后,还需要编辑tinymce.js
.所有需要的是编辑器removeformat
,例如:
After that, edit tinymce.js
is required too. All to need is editor removeformat
, for example:
removeformat: [
{selector: 'span', styles: ['background-color'], remove: 'empty', split: true, expand: false, deep: true}
]
(供其他用户使用)向面板添加新颜色,将此代码插入函数renderColorPicker()
中,建议在循环之前使用
(FOR OTHER USERS) to add new color to panel, insert this code in function renderColorPicker()
, recommended before loop:
function renderColorPicker() {
...
html += '<tr>';
html += (
'<td colspan="' + cols + '">' +
'<div id="' + ctrl._id + '-00" class="color-box"' +
' data-mce-color="transparent"' +
' role="option"' +
' tabIndex="-1"' +
' style="background-color: transparent"' +
' title="Default color">' +
'<span>Default color</span></div>' +
'</td>'
);
html += '</tr>';
for (y = 0; y < rows; y++){
...
这篇关于使用Java脚本删除HTML中的背景色和字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!