[英]How to change text colour and font weight if checkbox is checked with javascript?
我没有你的代码,但我假设你需要的是这样的。
你会有这样的 HTML
<p style="color: #FF0000; font-weight: bold;" id='termsText'>
I have read and agree to the terms and conditions
<input type="checkbox" name="termsChkbx"></p>
你的 javascript 应该是这样的。
var input1=document.getElementsByName('termsChkbx')[0];
input1.onclick=function(){
if(input1.checked){
document.getElementById('termsText').style="color:black; font-weight: bold;";
}else{
document.getElementById('termsText').style="color:red; font-weight: bold;";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.