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.
精彩评论