解读微信小程序操作 dom 样式
问题描述
想获取元素的 class 属性中设置的背景色,但非行内样式。
解答
根据小程序的设计理念,获取 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; };
在这种方法中,订单状态的色值与状态一起管理,便于获取和使用。
以上就是微信小程序如何获取非行内样式的元素背景色?的详细内容,更多请关注php中文网其它相关文章!
微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号