How do I put a variable in a string using javascript

前端 未结 4 588
慢半拍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 06:04

    As with most languages that don't have sigals, you can't perform interpolation, you have to concatenate multiple strings.

    "foo" + "bar" + "baz"
    "foo" + string_var + "baz"
    "+=" + string_var + "px"
    

提交回复
热议问题