[英]Alternate background color of form checkboxes
I'm making a simple form and want to alternate the background color of each option like you can for tables using CSS tr:nth-child(even){background-color: #f2f2f2;}
我正在做一个简单的表格,想像使用CSS
tr:nth-child(even){background-color: #f2f2f2;}
一样替换每个选项的背景色
For the form I tried using ids that linked to CSS with different background colors: 对于表单,我尝试使用链接到具有不同背景颜色的CSS的ID:
function options(){
var i =0;
var name;
$(xmlDoc).children().children().each(function(){
name = $(this).children().first().text();
if(i % 2 == 0){
$('form').append(" <input type='checkbox' id=odd'" + "value=" + name + ">"+ name + "<br>");
}
else{
$('form').append(" <input type='checkbox' id='even'" + "value=" + name + ">"+ name + "<br>");
}
i++;
});
}
but have found that you can only change the background color by indicating it in the form. 但发现您只能通过在表单中进行指示来更改背景颜色。 Is there any other way to do this?
还有其他方法吗?
Have you tried: 你有没有尝试过:
input[type="checkbox"]:nth-of-type(2n-1) {
background-color: #222222;
}
input[type="checkbox"]:nth-of-type(2n) {
background-color: #f2f2f2;
}
To change the color of the form you have to call it from the form 要更改表单的颜色,必须从表单中调用它
<form style="background-color: #E0FFFF"></form>
and can't do anything for specific inputs. 并且不能为特定输入做任何事情。 To combat this I have found that you have to turn the entire thing into a list and then can use
为了解决这个问题,我发现您必须将整个事情变成一个列表,然后才能使用
li:nth-child(even) {background-color: #f2f2f2;}
inside your CSS. 在您的CSS中。 The HTML looks like this:
HTML看起来像这样:
<ul style='list-style-type: none;><li><input type='checkbox' id='name' value='name'>name<br></li></ul>
the styling of the ul is to get rid of bullet points. ul的样式是摆脱要点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.