3 回答

TA貢獻1966條經驗 獲得超4個贊
你的問題不清楚。你是這個意思嗎?
var elements = document.getElementsByClassName("mat-button-wrapper");
for(var i = 0; i < elements.length; i++) {
elements[i].style.display = "none";
console.log("Hidden: " + elements[i]);
}

TA貢獻1864條經驗 獲得超2個贊
如果您想隱藏此按鈕:
<button class="mat-raised-button mat-primary" color="primary" mat-raised-button="">
<span class="mat-button-wrapper">RESET</span>
<div class="mat-button-ripple mat-ripple" matripple=""></div>
<div class="mat-button-focus-overlay"></div>
</button>
因為它包含這個詞 RESET
您可以使用以下內容:
// Get all relevant buttons
let myButtons = [...document.getElementsByClassName('mat-raised-button')];
// Cycle through buttons
myButtons.forEach((button) => {
let matButtonWrapper = button.getElementsByClassName('mat-button-wrapper')[0];
// Execute actions according to the mat-button-wrapper text
switch(matButtonWrapper.textContent) {
case ('RESET') : button.style.opacity = '0'; break;
// case ('Another word here') : actions here; break;
// case ('Another word here') : actions here; break;
// case ('Another word here') : actions here; break;
// case ('Another word here') : actions here; break;
}
});

TA貢獻1880條經驗 獲得超4個贊
首先你的問題不清楚,我不能很好地理解你到底想做什么以及你將如何做。如果您使用 JS ,請使用關鍵字 'this' , 'this' 將作用于按鈕觸發(fā)事件的當前范圍。
例子:
document.querySelector('button class').on('click', function() {
this.el.style.display = 'none'
});
當然,在事件函數中,您可以獲取單擊按鈕的值并檢查它的值。
或者您可以將 clicked el 傳遞給函數:
document.querySelector('button class').on('click', function(el) {
var value = el.value;
if(value === 'something') {
el.style.display = 'none'
}
});
添加回答
舉報