简体   繁体   English

将参数传递给包含“-”的javascript函数

[英]Passing parameter to a javascript function, which contains a '-'

I am trying to pass a parameter as text which contains multiple ' - '. 我正在尝试将参数传递为包含多个' - '的文本。

eg. 例如。 4f5ff225-70bc-4970-a12d-483beb066c47 4f5ff225-70bc-4970-a12d-483beb066c47

But when i pass it.. i get nothing in result. 但是当我通过它..我什么也没有得到结果。 I guess ' - ' is creating problem. 我猜' - '造成了问题。 Is there any way to pass the above example as it is to the javascript function. 有什么办法可以将上述示例传递给javascript函数。

I guess, your code looks something like this: 我想,您的代码看起来像这样:

 foo(4f5ff225-70bc-4970-a12d-483beb066c47)

This is not going to work and there should be some errors in the console. 这将无法正常工作,并且控制台中应该存在一些错误。

Pass it as a string (because that's what it is). 将其作为字符串传递(因为就是这样)。

 var foo = function(s) {
   alert(s);
 }

 foo('4f5ff225-70bc-4970-a12d-483beb066c47')

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

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