Salesforce 当LWC JS中超过最大字符限制时,是否有方法更改Lightning input富文本字段中的字体颜色?
我正在尝试获取字符数,并在此基础上更改字体的颜色 我已尝试使用Salesforce 当LWC JS中超过最大字符限制时,是否有方法更改Lightning input富文本字段中的字体颜色?,salesforce,salesforce-lightning,lwc,Salesforce,Salesforce Lightning,Lwc,我正在尝试获取字符数,并在此基础上更改字体的颜色 我已尝试使用queryselector(),但它不起作用: handleChange(event) { if( this.charCount > 100){ let textcolor = this.template.queryselector("lightning-input-rich-text"); textcolor.g
queryselector()
,但它不起作用:
handleChange(event) {
if( this.charCount > 100){
let textcolor = this.template.queryselector("lightning-input-rich-text");
textcolor.getformat({color:"red"});
}
}
我也尝试过:
handleChange(event) {
if( this.charCount > 100){
textcolor = this.template.queryselector('[data-id="summary"]');
if(textcolor)
this.template.querySelector('[data-
id="summarytextcolor"]').className='summarytext';
}
}
这是我的CSS:
.summarytext {color: #ff0000;}
这是我的lightning代码,其中我使用了一个富文本字段,在该字段中进行更改时,我需要捕获字符数:
<lightning-input-rich-text
data-id="summary"
label={label.Summary}
formats={richTextformats}
label-visible
valid={richTextValidity}
message-when-bad-input={richTextErrorMessage}
class="slds-form-element slds-form-element_stacked summarytext"
onchange={handleChange}
value={richTextValue}
style=" font-weight: normal;">
</lightning-input-rich-text>
问题出在哪里?我如何解决它?您应该能够使用vanilla javascript设置它
handleChange(event) {
this.loading = true;
if(this.charCount > 100){
var warn = richTextValue.fontcolor("Red");
this.richTextValue = warn;
}
this.loading = false;
}
我添加了一个变量“加载”;只需确保输入的富文本被包装在
中,以便重新呈现字体的颜色
handleChange(event) {
this.loading = true;
if(this.charCount > 100){
var warn = richTextValue.fontcolor("Red");
this.richTextValue = warn;
}
this.loading = false;
}