简体   繁体   English

如何将字符串参数传递给 javascript 方法

[英]How to pass string argument to javascript method

How to pass string argument to javascript method如何将字符串参数传递给 javascript 方法

my code我的代码

function paginatePage(getPath) {


    alert("from pagenate page");
    alert("home path initial " + getPath);
}

unable to get the alert message无法收到警报消息

when i called the method当我调用该方法时

[NSString stringWithFormat:@"paginatePage(%s)",getPath]

Probably just the quotes around the string literal missing?可能只是字符串文字周围的引号丢失了?

[NSString stringWithFormat:@"paginatePage('%s')",getPath]

You possibly need to qualify the string with quotes.您可能需要用引号限定字符串。

I don't know what that NSString syntax is, but something like:我不知道 NSString 语法是什么,但类似于:

[NSString stringWithFormat:@"paginatePage('%s')",getPath]

Your error does not come from this, because the code is 100% valid: this is how you pass a string argument to a function.您的错误并非由此而来,因为代码 100% 有效:这就是您将字符串参数传递给 function 的方式。

If you could provide some more code, maybe we could help you.如果您可以提供更多代码,也许我们可以帮助您。

Also, make sure no other function has the same name, or maybe it's how you called the function?另外,请确保没有其他 function 具有相同的名称,或者可能是您如何称呼 function?

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

相关问题 如何将字符串变量作为参数传递给javascript函数? - How to pass a string variable as an argument to a javascript function? 如何将字符串参数传递给javascript函数 - How to pass String Argument to javascript function 如何在Javascript中将字符串传递给对象方法? - How to pass a string into the object method in Javascript? 如何将Json字符串作为javascript方法参数传递 - How to pass Json string as a javascript method parameter 如何在javascript函数中向Ruby'send'方法传递参数? - How to pass an argument to Ruby 'send' method inside javascript function? Javascript:如何将参数传递给不带括号的被调用方法 - Javascript: How to pass an argument to a method being called without parentheses 如何从PHP端传递JavaScript函数中的数组字符串作为参数? - how to pass array string in JavaScript function from PHP end as a argument? JavaScript:如何将字符串参数传递给函数以用于按该字符串参数的值对对象数组进行排序? - JavaScript: How do I pass a string argument to a function to use to sort an array of objects by the value of that string argument? 如何将参数传递给 getElementById 方法? - How to pass an argument to a getElementById method? 将JavaScript回调作为Java方法参数传递 - Pass javascript callback as java method argument
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM