简体   繁体   English

如何串联javascript变量

[英]How to concatenate javascript variable

This may be a small issue but I am not getting rid of this . 这可能是个小问题,但我并没有摆脱它。 I want to concatenate the argument in a javascript function . 我想在javascript函数中连接参数。 This is my string 这是我的弦

html+='<a href="javascript:showchart('+data.code+');">';

data.code value is md5 string . data.code值是md5字符串。 But if i do like this it throws the error that fe741b62ff720a180a5960c4a2c50b27 is not defined . 但是,如果我这样做,则会引发错误,即fe741b62ff720a180a5960c4a2c50b27

I know it is taking this as constant, but how can I pass this as string within this html . 我知道这是常量,但是如何在html中将其作为字符串传递。

You want to pass a string, then you need to wrap variable in quotes, eg: 您想传递一个字符串,然后需要将变量用引号引起来,例如:

html+='<a href="javascript:showchart(\''+data.code+'\');">';

//<a href="javascript:showchart('fe741b62ff720a180a5960c4a2c50b27');">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM