为什么css后台jQuery代码不工作jQuery设置多个css值
Why css background jQuery code is not working jQuery set multiple CSS values
我正在尝试使用jQuery添加背景,但此代码不工作
$("#search").css({'background':'url(imageurl) no-repeat center center;width:32px;height:32px;'});
只有下面的代码有效
$("#search").css({'background':'url(imageurl) '});
我想用jquery实现这个
background:url(spinner.gif) no-repeat center center;width:32px;height:32px; **At least add the reason for downvote..........**
您需要将每个CSS规则放在对象的自己的属性中。试试这个:
$("#search").css({
'background': 'url(imageurl) no-repeat center center',
'width': '32px',
'height': '32px'
});
更好的是,将这些规则放入样式表中的一个类中,并使用addClass()
代替。这更可取,因为它将CSS逻辑从JS中分离出来。
在下面使用like
$("#search").css({'background': 'url(imageurl) no-repeat center center','background-size':'32px 32px'});
或
$("#search").css({'background': 'url("imageurl") no-repeat scroll center center / 32px 32px'});
相关文章:
- 每个选择器的Jquery css颜色都在变化,但字体大小却没有变化
- 自定义Jquery css下拉菜单问题
- jQuery css可见性在load方法中不起作用
- PNG图像被覆盖,但每个图像都有一个链接可以更改,每次一个-Javascript/jQuery/CSS
- Jquery CSS背景图像旋转
- 使用jQuery.css()方法时,是否需要转义任何字符
- 将jQuery.css()与变量一起使用
- 如何在jQuery.CSS()方法中为所有浏览器编写CSS代码
- 使用 js/jQuery/css 在重力形式中覆盖 !important
- 投资组合扩展器宽度 - Jquery CSS
- jQuery .css body opacity
- 当到达屏幕顶部时,jquery/css转换
- 如何防止文本区域在打字和进入页面底部时跳舞?:JQuery/CSS
- 在没有特定属性的情况下使用jQuery.css()
- 如何在HTML+jQuery+CSS中显示弹出窗口
- jQuery css"点击“;不会'更改日历中选定的月份后无法工作
- jQuery .css() 返回像素而不是百分比
- jquery css没有'我的情况不太好
- Jquery/CSS:全尺寸背景图像
- jquery.css()中的变量