繁体   English   中英

JQuery 使用 rgb 查找样式以替换为十六进制颜色

[英]JQuery find style with rgb to replace with hex color

我正在处理我的 jquery 脚本,以找到带有颜色和 rgb 的样式,我想找到用#444444替换它。 我在查找样式颜色时遇到了问题,因为当我尝试这样做时:

$('#text_editor').find('[style*="color: rgb(68, 68, 68)]"').css('color', '#444444');

它不会让我找到带有颜色和 rgb 的样式,因为它不会替换它。

我也试过这个:

$('#text_editor').find('color: rgb(68, 68, 68)').css('color', '#444444');

和这个:

document.execCommand('foreColor', false, '#444444');
$('#text_editor').find("span[style*='color: rgb(68, 68, 68)']").css('color', '#444444');

它没有什么不同,因为我不断得到这个:

<span style="color: rgb(68, 68, 68);">sdgsdgsdgsdgsdg</span>

这是我想要实现的目标:

<span style="color: #444444;">sdgsdgsdgsdgsdg</span>

这是html:

<div id="text_editor" class="editor_message" hidefocus="false" aria-label="Message Body" g_editable="true" role="textbox" aria-hidden="true" aria-multiline="true" contenteditable="true" tabindex="1" style="direction: ltr; height: 500px; width: 100%; padding-left: 25px; padding-top: 18px; font-size: 16px; border-bottom: 1px solid #d1d1d1; border-right: 1px solid #d1d1d1; border-left: 1px solid #d1d1d1; overflow-y: auto;" itacorner="6,7:1,1,0,0">
    <span style="color: rgb(68, 68, 68);">sdgsdgsdgsdgsdg</span>
</div>

这是完整的代码:

$(document).on('click', '#color-picker1', function(e) {

    $('#color-picker' + colorpicker_number + ' div').removeClass('tick-color');
    $('#color-picker' + colorpicker_number).removeClass('color-picker-border');
    $('#color-picker1 div').addClass('tick-color');
    $('#color-picker1').addClass('color-picker-border');
    colorpicker_number = 1;
    alert("time to change the color 6");
    document.execCommand('styleWithCSS', 0, true);
    document.execCommand('foreColor', false, '#444444');
    $('#text_editor').find('[style*="color: rgb(68, 68, 68)"]').css('color', '#444444');

    if ($('#toolbar_text_color').css('display') == 'block') {
        $('#toolbar_text_color').hide();
    }
    $('#text_editor').focus();
});

你能告诉我一个例子,在我可以使用 css 将它替换为#444444之前,我如何找到我想要找到的带有 rgb 颜色的样式吗?

谢谢你。

如果您在 div 或其他元素中使用它,它不会改变。

我唯一知道它会可见的是当你用背景颜色的 css 做它时。

<div style="background-color: #444444;">
...
</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM