javascript - 如何使用 vanilla js 和 sass 创建可重用的按钮组件?
问题描述
我必须用 vanilla js 和 scss 制作一个可重用的按钮组件,但我还没有完成。有人可以解释我该怎么做吗?我是新手,所以我不知道在哪里寻找它。
更新:我必须使用 javascript 还是只能使用 HTML 和 SCSS/CSS?
解决方案
有很多解决方案可以做到这一点。一个简单的解决方案是在不同子类之间的 css 和 toogle 上创建样式,然后创建一个方法或函数来返回该组件的值。
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 );
推荐阅读
- yocto - 我如何找出导致包含食谱的原因?
- javascript - 比较两个对象中选定属性的最佳方法是什么
- algorithm - 地形的保留步骤算法/反带状算法?
- twitter - 使用 Tweepy 从用户 Twitter 关注者那里获取用户 ID 列表
- javascript - 使用 Javascript 在按下按钮时播放随机歌曲
- macos - 使用 VS 2019 从 Windows 10 部署 UNO 平台 macOS 应用程序
- spring-boot - 在 Spring Boot 应用程序之间未正确发送 Trace Id
- java - 可变实例对象的可见性
- python - 从别名表急切加载关系时出现“不从元素链接”错误
- php - MERGE INTO USING from dual (ORA-00923 FROM 关键字未在预期的地方找到)