jQuery .css()函数包含变量和多个值 [英] jQuery .css() function with variables and multiple values

查看:181
本文介绍了jQuery .css()函数包含变量和多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

奇怪的小麻烦。我正在使用jQuery的 .css()方法来改变文本的大小(长篇故事;不,我不能使用媒体查询)使用变量我需要添加 em 。我不确定语法是什么,因为CSS更改有多个值。

Weird little snafu. I'm using jQuery's .css() method to change the size of text (long story; no, I can't use media queries) using a variable and I need to add em to it. I'm not sure what the syntax is because there are multiple values for the CSS change.

举例说明:

这完美无缺。它将 em 添加到计算值 victore

This works perfectly. It adds em to the calculated value of victore:

$('h1').css('font-size', victore + 'em');

这不是:

$('h1').css({
    'font-size':victore + 'em',
    'line-height':vignelli + 'em';
});

em 需要报价...但是价值也是如此。将其包裹在parens中无法正常工作

The em needs quotes... but so does the value. Wrapping it in parens didn't work

推荐答案

你不应该在整个事情中引用:

You shouldn't have the quotes around the whole thing:

$('h1').css({
    'font-size': victore + "em",
    'color':'red'
});

这篇关于jQuery .css()函数包含变量和多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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