variable in javascript statement

后端 未结 2 835
暖寄归人
暖寄归人 2021-01-05 05:18

How does one add a variable string in this javascript statement? where name may correspond to any valid string , say WebkitTransform or Moztransform,etc

docu         


        
相关标签:
2条回答
  • 2021-01-05 06:02

    There are 2 ways of accessing values in javascript objects. The first one is by using the dot operator(e.g. object.memberName). The second one is by using the square bracket notation(e.g. object['memberName']).

    0 讨论(0)
  • 2021-01-05 06:04

    There are two ways to access members of a Javascript object.

    Dot notation, which uses an identifier to access the member:

    obj.member;
    

    Bracket notation, which uses a string to access the member:

    obj['member']
    

    The latter uses a string to locate the member and you can just as easily use any expression. The value of the expression will be converted to a string so these are equivalent:

    obj[{}]
    obj['[object Object]']
    

    If your expression is already a string it will be used as is, and in your case your variable holds a string so you can just do:

    document.getElementById('test').style[VARIABLE_NAME]  =  'rotate(15deg)';
    
    0 讨论(0)
提交回复
热议问题