![](/img/trans.png)
[英]How do I put the contents of a variable to the clipboard using javascript?
[英]How do I put a variable in a string using javascript
如何在JavaScript中将变量放入字符串中?
例:
$('#contactForm').animate({"marginLeft": "+=680px"}, "slow");
我想在变量而不是680px
,有没有办法做到这一点?
与大多数没有符号的语言一样,您无法执行插值,必须连接多个字符串。
"foo" + "bar" + "baz"
"foo" + string_var + "baz"
"+=" + string_var + "px"
var size = "680px";
$('#contactForm').animate({"marginLeft": "+="+size}, "slow");
您可以使用+
运算符将变量中的值连接到"+="
字符串:
$('#contactForm').animate({"marginLeft": "+=" + size}, "slow");
var theWidth = "680px"
$('#contactForm').animate({marginLeft: "+=" + theWidth}, "slow");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.