Javascript jQuery:有可能获得css值数组吗?
我希望通过用图像替换表单元素来设计radio和checkbox表单元素。我希望能够设置复选框的样式,并让jquery生成一个值数组 大概是这样的:Javascript jQuery:有可能获得css值数组吗?,javascript,jquery,html,css,stylesheet,Javascript,Jquery,Html,Css,Stylesheet,我希望通过用图像替换表单元素来设计radio和checkbox表单元素。我希望能够设置复选框的样式,并让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);
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值存储在一个数组中,并遍历它们并将它们分配给一个范围
$("input[type=checkbox]").after('<span style="'+cssValuesHere+'"></span>');
$(“输入[type=checkbox]”)。在(“”)之后;
尝试使用以下方法:
.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>');
.css\u类{
宽度:13px;高度:13px;
/*.css()不能接受shorhand背景属性我不认为*/
背景图片:url(assets/img/bg_form_checkbox.gif);
背景重复:无重复;
背景位置:50%50%;
位置:相对位置;
}
美元(“.css_class”)。在(“”)之后;
var cssValues={
宽度:'13px',
高度:'13px',
背景图片:“url(assets/img/bg_form_checkbox.gif)”,
背景重复:“不重复”,
背景位置:“50%50%”,
位置:'相对'
}
$(“”).css(cssValues).insertAfter(“输入[type=checkbox]”);
+1获得一个好答案。我想说@bjornd的答案更好,但两者都很好。谢谢,我最后使用了类似的东西。我将这些类命名为.checkbox、.radio和.select,并让jQuery将适当的类应用于一个范围,该范围将替换任何需要样式设置的输入类型。
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]");