javascript - Flipswitch - 如何将翻转开关状态存储在变量中?

标签 javascript html switch-statement

我想使用在以下位置生成的翻转开关代码:

https://www.cssportal.com/css3-flip-switch/

我是一名电工,而不是一名全职程序员。我想用这个颂歌来控制树莓派输出。简而言之,我希望当翻转开关打开时变量等于 1,关闭时变量等于 0。

谢谢

最佳答案

您可以通过获取对象并在其上设置 EventListener 来保存状态。每次单击开关时,它都会更新 state 变量。

var state;

document.getElementById('fs').addEventListener('click', saveState);

function saveState() {
    state = document.getElementById('fs').checked;
}

然后,状态中有一个 bool 值,即 truefalse

关于javascript - Flipswitch - 如何将翻转开关状态存储在变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55072877/

相关文章:

javascript - 如何在 laravel 中加载多选的相关下拉菜单

jquery - CSS3 - 动画背景图像过滤器

javascript - 使用 JavaScript 获取 href 值并在新窗口中打开它

java - 在 JNI 中打开枚举?

Javascript : how to get the name of the instance?

javascript - 在 React 中管理大型状态树

javascript - typescript :如何在 Object.entries().forEach([key,value]) => 中正确键入键和值参数

html - 如何在表格中添加垂直标题

C: 使用 getchar 和 switch case 获取主菜单的用户输入的问题

java - 如何在 android studio 中的复选框的 switch case 语句中使用 OR