我希望通过用图像替换表单元素来设置收音机和复选框表单元素的样式。我希望能够设置复选框的样式并让jquery创建值的数组。
这样的事情:
input[type=checkbox] {
width:13px;height:13px;
/*.css() can't take the shorhand background property I don't think*/
background-image:url(assets/img/bg_form_checkbox.gif);
background-repeat:no-repeat;
background-position:50% 50%;
position:relative;
}
有没有办法将css值存储在一个数组中并迭代它们并将它们分配给一个span?
$("input[type=checkbox]").after('<span style="'+cssValuesHere+'"></span>');
答案 0 :(得分:3)
尝试使用它:
.css_class {
width:13px;height:13px;
/*.css() can't take the shorhand background property I don't think*/
background-image:url(assets/img/bg_form_checkbox.gif);
background-repeat:no-repeat;
background-position:50% 50%;
position:relative;
}
$(".css_class").after('<span class="css_class"></span>');
答案 1 :(得分:1)
var cssValues = {
width:'13px',
height:'13px',
background-image: 'url(assets/img/bg_form_checkbox.gif)',
background-repeat: 'no-repeat',
background-position: '50% 50%',
position:' relative'
}
$('<span/>').css(cssValues).insertAfter("input[type=checkbox]");