【问题标题】:How to create reusable button component with vanilla js and sass? [closed]如何使用 vanilla js 和 sass 创建可重用的按钮组件? [关闭]
【发布时间】:2019-11-07 06:45:25
【问题描述】:

我必须用 vanilla js 和 scss 制作一个可重用的按钮组件,但我还没有完成。有人可以解释我该怎么做吗? 我是新手,所以不知道去哪里找。

更新:我必须使用 javascript 还是只能使用 HTML 和 SCSS/CSS?

【问题讨论】:

标签: javascript html css sass web-component


【解决方案1】:

有很多解决方案可以做到这一点。一个简单的解决方案是在不同子类之间的 css 和 toogle 上创建样式,然后创建一个方法 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 );

【讨论】:

    猜你喜欢
    • 2022-10-16
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 2020-06-03
    • 2019-11-05
    • 1970-01-01
    相关资源
    最近更新 更多