0

我的javascript方法是从objective c调用的,我试图将从objective接收到的值放在html的文本框中。起初它来了,但随后页面被刷新,文本框失去了价值

function square(val)
{
alert('Entered value is ="+val);
document.getElementById('txtshow').value=val; 
}

piece of code written in objective c from where i am calling javascript is-
(i am calling this javascript on button's click)

-(IBAction)btnResultClicked:(id)sender
{
 NSString *function=[NSSTring stringWithhFormat:@"square(%d)",val];
 [webView loadHTMLSt5ring:strFile baseURL:nil];
 [webView stringByEvaluatingJavaScriptFromString:function];
 webView.backgroundColor=[UIColor clearColor];
 [self.view addSubView:webView];
 }
4

1 回答 1

0

当您在其上执行 javascript 时,似乎strFile尚未加载到 webView,也许您可​​以在 web 视图完成加载后尝试执行 javascript:

- (void) webViewDidFinishLoad:(UIWebView *)webView {
    NSString *function=[NSSTring stringWithhFormat:@"square(%d)",val];
    [webView stringByEvaluatingJavaScriptFromString:function];
}
于 2013-04-16T09:47:23.090 回答