开发者

Change a String

开发者 https://www.devze.com 2023-04-12 18:11 出处:网络
Not sure how to ask this question, but here goes. Say I have: var foo = \'marginLeft\'; How can I change it into:

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

精彩评论

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