0
這裏是我想要一個簡單的「addClass」的功能,但它不工作。應該是一個簡單的事情,坐在代碼中的某處)))。文本應該改變基於用戶在radioGroup1選擇的顏色在這裏http://jsfiddle.net/PatrickObrian/gdb5t/addClass不工作
HTML
<div class="test">Information that I want to be coloured</div>
<div>
<label><input type="radio" id="A" name="RadioGroup1" value="Y">Yes</label>
<br>
<label><input type="radio" id="B" name="RadioGroup1" value="N">No</label>
</div>
JS
<script>
$('input[type=radio][name=RadioGroup1]').change(function(){
if (this.value == 'Y') {
$('.test').addClass("classGreen");
}
else if (this.value == 'N') {
$('.test').addClass("classRed");
}
}
</script>
CSS
.classGreen {color: green}
.test {font-size:24px}
.classRed {color: red}
提前感謝!
哦謝謝!!!!我必須包含jQuery的addClass功能嗎? – Alexander
@Alexander'$'表示'jQuery'。如果你使用它,它必須包括在內。 –
啊,我明白了,謝謝。剛開始使用Javascript。 – Alexander