HTML:操縱複選框使用jQuery
<form>
<label>
<input type="radio" name="news" value="right" id="right">Show News on the right
</label>
<br>
<label>
<input type="radio" name="news" value="left" id="left">Show News on the left
</label>
<br>
<label>
<input type="color" name="bgcolor" value="#ffffff">Set background color
</label>
<br>
<label>
<input type="checkbox" name="color_scheme" value="green" id="green">Show green colors
</label>
<br>
<label>
<input type="checkbox" name="color_scheme" value="red" id="red">Show red colors
</label>
</form>
<br>
<button>Customize!</button>
JS:
$(document).ready(function() {
if ($('#green').prop('checked') == true) {
$('body').css('background-color', 'green');
}
});
嘿,我怎麼操縱的複選框,這樣它會在「綠轉個身的背景顏色爲綠色「被選中,用紅色做同樣的事情,當兩者都被選中時,綠色被選作背景。此外,是否可以標記複選框並僅在單擊「自定義」按鈕時應用更改?
還好,但如果兩者都選中,它必須是綠色的。如果沒有檢查 - 白色,所以它不會工作,我想 – szubansky
@szubansky這不適合你?差不多是 –