为什么以下工作?
<something>.stop().animate(
{ 'top' : 10 }, 10
);
Run Code Online (Sandbox Code Playgroud)
虽然这不起作用:
var thetop = 'top';
<something>.stop().animate(
{ thetop : 10 }, 10
);
Run Code Online (Sandbox Code Playgroud)
为了使它更清晰:目前我无法将CSS属性作为变量传递给animate函数.
我想为'myObj'添加一个新属性,将其命名为'string1'并赋予它'string2'的值,但是当我这样做时它会返回'undefined:
var myObj = new Object;
var a = 'string1';
var b = 'string2';
myObj.a = b;
alert(myObj.string1); //Returns 'undefined'
alert(myObj.a); //Returns 'string2'
Run Code Online (Sandbox Code Playgroud)
换句话说:如何创建一个对象属性并为其赋予存储在变量中的名称,而不是变量本身的名称?