[英]Javascript stringByEvaluatingJavaScriptFromString not posting
So I have the following file which contains the following javascript 所以我有以下文件,其中包含以下javascript
(function getradiovalue(myvalue)
{
alert(myvalue);
return myvalue;
})
My .m file contains the following 我的.m文件包含以下内容
NSString thisinputradio = @"radio1";
NSString *tstr = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"getRadioValue" ofType:@"txt"] encoding:NSASCIIStringEncoding error: &error] ;
NSString *injectstr = [webView stringByEvaluatingJavaScriptFromString:tstr] ;
NSString *myjscript = [NSString stringWithFormat:@"getradiovalue('%@');", thisinputradio];
NSString *evalstr = [webView stringByEvaluatingJavaScriptFromString:myjscript] ;
This should throw my alert with the value that I have assigned to thisinputradio but I'm getting nothing. 这应该使我的警报与我分配给此inputradio的值,但我什么也没得到。 I threw an NSLog(@"%@", tstr);
我扔了一个NSLog(@“%@”,tstr); and it spits out the javascript code but when I evaluate the second half to pass a variable into the function i get squat.
并且它吐出了javascript代码,但是当我评估后半部分以将变量传递给函数时,我会蹲下。 Any Help is much appreciated.
任何帮助深表感谢。 I would like to be able to pass something into the getradiovalue function multiple times which is why I have it broken apart this way.
我希望能够多次将某些内容传递到getradiovalue函数中,这就是为什么我将这种方式分解开来的原因。
取下功能周围的第一个和最后一个括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.