繁体   English   中英

以变​​量作为参数调用Javascript函数

[英]Calling Javascript function with variables as parameters

如何调用javascript函数并传递一些变量以用作实例参数

说函数javascriptFunction使用2个参数。 我通常将其称为javascriptFunction("param1", "param2") (在字符串javascriptFunction("param1", "param2")加上单引号)。 但是现在我想给它传递一些变量。

string y = "this is a string"
string x = "another"
javascriptFunction(y, x)

我已经尝试过javascriptFunction(@y, @x) @y,@x javascriptFunction(@y, @x) ,javascriptFunction(“ @ y”,“ @x”)(在字符串javascriptFunction(@y, @x)用单引号和双引号引起来),但这不起作用

编辑我实际上是通过视图(cshtml文件)进行呼叫。 所以我的变量是字符串。

JavaScript具有弱类型系统。 无需指定类型。 所有变量的类型均由其值确定。 它们是使用关键字var创建的:

var y = "this is a string";
var x = "another";

[并且不要忘记使用分号!]

这应该工作

var y = "this is a string", x = "another";
javascriptFunction(y, x);

暂无
暂无

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

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