Jquery .css()语法 [英] Jquery .css() syntax

查看:126
本文介绍了Jquery .css()语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么有时候使用','vs':'分隔.CSS参数?

Why are there times when you use a ',' vs ':' to separate .CSS parameters?

例如:

$('#example').css("",""); vs. $('#example').css("":"");

我以这种方式使用。

$('#example').css("color","#000000");
$('#example').css("cursor":"pointer");


推荐答案

冒号仅在您必须指定多个值。但是,然后你必须把值放在括号和大括号中,并用逗号分隔。
例如:

The colon is only used when you have to specify multiple values. But then you have to put the values in brackets and curly brackets and separate them by a comma. For example:

$('#example').css({
  'background-color' : 'yellow',
  'font-weight' : 'bolder'
});

否则,当您只需要设置一个值时,可以使用逗号:

Otherwise, when you only need to set one value, you use the comma:

$('#example').css('background-color','yellow');

这篇关于Jquery .css()语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆