javascript - 在 chrome 扩展中存储和检索复选框的值
问题描述
我正在制作一个 chrome 扩展,我希望能够保存和读取复选框的状态(格式化为一个开关)以影响程序的运行方式。
目前我什至无法以任何方式访问该复选框,因为我以前从未以任何身份使用过 javascript。为了测试我是否可以读取当前状态,我使用了 console.log(document.getElementById("activeSwitch").checked) 或其一些变体。
这是我用来创建按钮的弹出 html
<head>
<title>test</title>
<script src="popup.js"></script>
<style>
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
</head>
<body>
<div>
<p><b>test extension</b></p>
<label id="activeSwitch" class="switch">
<input type="checkbox" checked/>
<span class="slider round"></span>
</label>
</div>
</body>
解决方案
推荐阅读
- python - 从 3D 数组中提取第 n 个值
- python - 使用 Python 来抓取linkedin 连接,但只显示了一些 - Selenium 和 BeautifulSoup
- python - 'c' 和 'value' 是什么?有人可以解释这些是如何工作的吗?
- c# - 使用 MVC Core 捆绑和缩小
- r - 如何从数据框列中提取唯一值?
- java - 将txt文件读入邻接矩阵
- linux - 我想以某种方式获得Linux中文件的唯一标识符,有什么想法吗?
- python - 如何根据用户输入的内容打印一个多面体的体积?
- codeigniter - CodeIgniter 控制器实例化:什么时候发生?
- swift - Alamofire 和响应 allHTTPHeaderFields 问题