[英]Colour radio buttons on form validation - Javascript
Currently I have this: 目前我有这个:
function validateRadio(x){
if(document.getElementById(x).checked){
return true;
}else{
return false;
}
}
Heres the HTML: 以下是HTML:
<strong> Smoking Area? </strong>
<br>
Yes <input type="radio" name="hand" id="left" value="Left" onblur="validateRadio(id)"/>
No <input type="radio" name="hand" id="right" value="Right" onblur="validateRadio(id)"/>
<span class="validateError" id="handError" style="display: none;">Please specify whether you would like a table in the smoking area.</span>
<br><br>
However I want this to show up as red if no radio button is clicked or green if once is and it passes Validation, would this be possible? 但是,如果没有单击单选按钮,我希望它显示为红色,如果一次通过验证,则希望显示为绿色,这可能吗?
Also, I want the warning to be hidden once a radio button is clicked, currently it stays on the page. 另外,我希望单击一次单选按钮后隐藏警告,目前它停留在页面上。 Any help would be appreciated :)
任何帮助,将不胜感激 :)
Not quite clear what exactly you want to paint, but if you're talking about the radio buttons themselves, I think it would be a much better idea to design your own buttons (images with on and off states) and use them instead. 尚不清楚您到底要绘制什么,但是如果您谈论的是单选按钮本身,我认为设计自己的按钮(具有打开和关闭状态的图像)并使用它们来替代是一个更好的主意。 That way you'll be able to maintain crossbrowser consistency as well as a much nicer/custom look to your site.
这样,您将能够保持跨浏览器的一致性以及对站点的更好/自定义的外观。
However, you're talking about the text parts ("Smoking Area", "yes/no"), the easiest way would be to give their container an id, and then do something like: 但是,您在谈论文本部分(“吸烟区”,“是/否”),最简单的方法是为其容器指定一个ID,然后执行以下操作:
function validateRadio(x){
if(document.getElementById(x).checked){
document.getElementById('your_container').style.color = 'green';
return true;
}else{
document.getElementById('your_container').style.color = 'red';
return false;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.