Assigned expression type string is not assignable to type CSSStyleDeclaration
According to mdn, HTMLElement.style should be treated as read-only and not used to set a style attribute string; instead it is a CSSStyleDeclaration, as IntelliJ has informed you.
If you're dead set on specifying style as a string, you can do so using, e.g., element.style.cssText = 'border: 2px solid red'.
EDIT: to further narrow the answer to your question, the consequence is that you no longer have access to the CSSStyleDeclaration object and as it is an unsupported means of setting style, you risk inconsistent results or broken code.
使用element.style.cssText
代替element.style
,element.style
应该作为只读
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 大模型 Token 究竟是啥:图解大模型Token
· 35岁程序员的中年求职记:四次碰壁后的深度反思
· 继承的思维:从思维模式到架构设计的深度解析
· 如何在 .NET 中 使用 ANTLR4
· 后端思维之高并发处理方案
· 感觉程序员要被 AI 淘汰了?学什么才有机会?
· MQTT协议发布和订阅的实现,一步步带你实现发布订阅服务。
· Dify开发必备:分享8个官方文档不曾解释的关键技巧
· 活动中台系统慢 SQL 治理实践
· “你觉得客户需要”是杀死TA的最后一根稻草 | IPD集成产品开发