2
我使用Material Components Web創建網站。我有一個類.mdc-button
的按鈕列表,我用下面的代碼將它激活到我的Javascript文件中。材料組件Web - mdc attachTo僅適用於第一個元素
window.button = new mdc.ripple.MDCRipple.attachTo(document.querySelector('.mdc-button'));
的問題是,這僅適用於第一個元素與類.mdc-button
這是爲什麼,以及如何解決它?
我想'window.button =新mdc.ripple.MDCRipple.attachTo(document.getElementsByClassName( 'MDC-按鈕'));'和' window.button = new mdc.ripple.MDCRipple.attachTo($(「。mdc-button」));'但它只是沒有選擇。 –
您需要遍歷getElementsByClassName的結果,檢查我的編輯 – Surreal