如何使用javascript将变量放入字符串中 [英] How do I put a variable in a string using javascript
本文介绍了如何使用javascript将变量放入字符串中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 JavaScript 中将变量放入字符串中?
How do I put a variable in a string in JavaScript?
示例:
$('#contactForm').animate({"marginLeft": "+=680px"}, "slow");
我想在变量中使用而不是 680px
,有没有办法做到这一点?
I would like to use in a variable instead of 680px
, is there a way to do this?
推荐答案
与大多数没有信号的语言一样,您无法执行插值,您必须连接多个字符串.
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"
这篇关于如何使用javascript将变量放入字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文