[英]primeng how to inline style checkbox?
如何使用p-checkbox
的style
輸入來改變復選框的邊框和背景顏色? 我已經嘗試過[style]="{'background': '#ff0000'}"
。 但這僅將樣式應用於包含實際復選框的 div。 所以沒用。 相反,我需要更改具有類p-checkbox-box
和p-highlight
的 div 的border-color
和background
。 注意:我不能在這里使用 CSS,因為 colors 是動態的並且依賴於內容。
您可以使用 renderer2 來操作 DOM 元素,然后添加樣式:
使用document.getElementsByClassName('p-checkbox-box')
獲取所有復選框
遍歷每個元素並使用renderer2.setStyle()
添加你想要的樣式
嘗試這段代碼並將其添加到ngAfterViewInit()
中:
let chkboxes = document.getElementsByClassName('p-checkbox-box')
for (let index = 0; index < chkboxes.length; index++) {
const element = chkboxes[index];
this._renderer2.setStyle(element,'background-color','#bf2222');
this._renderer2.setStyle(element,'border-color','#bf2222');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.