我想改變使用複選框的元素的背景位置,但不工作。Javascript複選框來改變背景不工作
下面是代碼:
x = false;
function Check() {
if (x) {
document.getElementById("checkboz").style.backgroundPosition = '0 0';
document.getElementById("checkboz").style.backgroundPosition = '-28px 0';
x = false;
} else {
document.getElementById("checkboz").style.backgroundPosition = 'none';
document.getElementById("checkboz").style.backgroundPosition = '0 0';
x = true;
}
}
#checkboz {
background: url(http://movimientomore.com/images/2016/12/21/sprite-check-01.png);
background-size: 55px;
background-repeat: no-repeat;
width: 28px;
height: 28px;
}
<div id="checkboz" class="checkbox">
<label for="modlgn-remember">
<input id="modlgn-remember" name="remember" class="inputbox" value="yes" type="checkbox">Recordarme</label>
</div>
非常感謝你的幫助:)
如何調用你的函數?你根本沒有調用函數? – sinisake
將'onclick =「Check()」'添加到複選框。 – Barmar
Check()永遠不會被調用。 – Korgrue