[OK]を、あなたは私がコード
HTMLコメントしてきたJSに慣れていないので、:
<body>
<p>
test
</p>
<label class="switch">
<input type="checkbox" id="test">
<span class="slider round"></span>
</label>
JS:
var checkedColor="red"; //the colors of the background
var uncheckedColor="blue" //the colors of the background
document.body.style.backgroundColor =uncheckedColor;//change the color at the begining to keep it consistent
function changeColor(){
if (document.getElementById("test").checked) { //if it is checked change to checkedColor
document.body.style.backgroundColor = checkedColor;
}
else {//if it is not checked change to uncheckedColor
document.body.style.backgroundColor =uncheckedColor;
}
}
document.getElementById("test").addEventListener('click', changeColor); //make the checkbox exeute the function test when being clicked
ここでは、実施例です。 https://jsfiddle.net/25t64qha/
jQueryを使用していますか? – user2887596
いいえ、私はjQueryを使用していません。 – Miner123
これまでに試したことを含めてください – Nick