跳转到主内容
趣航编程网 - 趣学编程,启航技术之路!

微信小程序如何获取非行内样式的元素背景色?

解读微信小程序操作 dom 样式 问题描述 想获取元素的 class 属性中设置的背景色,但非行内样式。 解答 根据小程序的设计理念,获取 DOM 属性通常是不可行的。然而,可以尝试以下方法: 微信 WeLM WeLM不是一个直接的对话机器人,而是一个补全用户输入信息的生成模型。 下载 使用 querySelector* 或 getElement* 获取 DOM 元素,但成功与否尚不确定。 转换思路,将需要操作的颜色值与属性/状态一起管理,以便在使用时更加便捷。 实际代码示例
export const orderProcess = { default: { label: '默认', color: "#848484", key: 0 }, pre: { label: '沟通中', color: "#ffd36e", key: 1 }, ... finish: { label: '订单完成', color: "#87d068", key: 8 }, cancel: { label: '作废', color: "#dedede", key: -1 }, }; // 订单状态集合 export const orderProcessList = Object.values(orderProcess); // 获取订单状态 export const getOrderProcess = function (key) { const finder = orderProcessList.find((item) => item.key === Number(key)); return finder || ErrorData; };
在这种方法中,订单状态的色值与状态一起管理,便于获取和使用。

相关文章