How do I put a variable in a string using javascript

前端 未结 4 581
慢半拍i
慢半拍i 2021-01-26 05:51

How do I put a variable in a string in JavaScript?

Example:

$(\'#contactForm\').animate({\"marginLeft\": \"+=680px\"}, \"slow\");

I wou

4条回答
  •  无人及你
    2021-01-26 05:55

    You can use the + operator to concatenate your value in a variable to the "+=" string:

    $('#contactForm').animate({"marginLeft": "+=" + size}, "slow");
    

提交回复
热议问题