开发者

Change a String

Not sure how to ask this question, but here goes.

Say I have:

var foo = 'marginLeft';

How can I change it into:

marginLeft

So this would be possible:

$(element).animate({foo: 20});

Please note, not looking for this (I want the curly braces):

$(element).animate开发者_如何学运维(foo,20);


Well, you should be able to get the same behavior with something like this:

var foo = "marginLeft";
var x = {};
x[foo]=20;

$(element).animate(x);


No, it is not possible. You can't use a variable as a object key. This is the limitation of the literal object syntax of javascript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜