我正在尝试获取字符数,并在此基础上更改字体颜色。
我试过了,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-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>
这是我得到的错误:
[NoErrorObjectAvailable] Script error. a()@https://static.lightning.force.com/cs10/auraFW/javascript/7p9HLMpgnV2GO9MqZhXGUw/aura_prod.js:948:169 {anonymous}()@https://static.lightning.force.com/cs10/auraFW/javascript/7p9HLMpgnV2GO9MqZhXGUw/aura_prod.js:948:362 bt.dispatchEvent()@https://static.lightning.force.com/cs10/auraFW/javascript/7p9HLMpgnV2GO9MqZhXGUw/aura_prod.js:12:12146 bt.dispatchChangeEvent()@https://customization-velocity-2311-dev-ed.lightning.force.com/components/interop/inputRichText.js:2:28144 eval()@https://customization-velocity-2311-dev-ed.lightning.force.com/components/interop/inputRichText.js:2:20578 e.l.emit()@https://customization-velocity-2311-dev-ed.lightning.force.com/components/lightning/quillLib.js:2:142032 e.value()@https://customization-velocity-2311-dev-ed.lightning.force.com/components/lightning/quillLib.js:2:33139
有什么问题,我该如何解决?