我必须使用香草js和scss制作一个可重用的按钮组件,但是我还没有做。有人可以解释我该怎么做吗?我是新来的,所以我不知道在哪里寻找。
更新:我必须使用JavaScript还是只能使用HTML和SCSS / CSS?
有许多解决方案可以做到这一点。一个简单的解决方案是在css上创建样式并在不同的子类之间切换,然后创建方法o函数以返回带有值的该组件。
var cusButton = (i_params ) => {
var curButton = document.createElement ('INPUT'), buttonContainer;
curButton.classList.add (i_params.classname);
curButton.type = 'button';
curButton.value = i_params.valueButton;
//the classname has the properties that you have to create before...
buttonContainer = document.getElementById
(i_params.idButContainer);
buttonContainer.appenChild (curButton);
}
//Then, create one object for each button and call this function to populate the DOM with the new buttons:
var propButton ={ classname : 'created-class', valueButton : 'Click here to sens', idButContainer : 'id-name-node'};
cusButton (propButton );