我正在使用 javascript 制作一些样式按钮,但它们不起作用

I am making some style buttons using javascript but they are not working

我正在使用 javascript 制作一些样式按钮,但它们不起作用。

我已经为此苦苦挣扎了几个小时。

这是我的代码:

Html:

<textarea><textarea>
<button onclick = "size('fontSize','10px',0)">Small</button>
<button onclick = "size('fontSize','20px',1)">Medium</button>
<button onclick = "size('fontSize','30px',2)">Large</button>
<button onclick = "size('fontSize','40px',3)">Extra Large</button>

JavaScript:

function size(stys,sizes,i){
                let buttons = document.getElementsByTagName('button')
                document.querySelector('textarea').style.stys = sizes;
                console.log(document.querySelector('textarea').style.stys)
                for(let y = 0;y<buttons.length;y++){
                   buttons[y].style.textDecoration = 'none'
                }   
                 buttons[i].style.textDecoration = 'underline'
            }

我不确定为什么,但是即使 console.log return 我想要样式化的字体大小,字体大小也不会样式化到文本区域。

感谢大家的帮助。

.style.stys改为.style[stys]:

function size(stys,sizes,i){
    let buttons = document.getElementsByTagName('button')
    document.querySelector('textarea').style[stys] = sizes;
    console.log(document.querySelector('textarea').style[stys])
    for(let y = 0;y<buttons.length;y++){
       buttons[y].style.textDecoration = 'none'
    }   
     buttons[i].style.textDecoration = 'underline'
}
<textarea></textarea>
<button onclick = "size('fontSize','10px',0)">Small</button>
<button onclick = "size('fontSize','20px',1)">Medium</button>
<button onclick = "size('fontSize','30px',2)">Large</button>
<button onclick = "size('fontSize','40px',3)">Extra Large</button>