2014-02-07 21 views
0

有可能嗎?如果我使用UIWebview調用本地HTML單選buttons.how可以從html獲取數據單選按鈕?帶單選按鈕的IOS(html5)

這裏的IOS代碼

for (int i = 0; i < [book count]; i++) { 
      CGRect frame = self.scrollView.frame; 
      frame.origin.x = self.scrollView.frame.size.width * i; 
      frame.origin.y = 0; 
      frame.size.height = scrollView.frame.size.height; 
      frame.size.width = scrollView.frame.size.width; 

      subView = [[UIWebView alloc] initWithFrame:frame]; 
      subView.scalesPageToFit = YES; 
      subView.backgroundColor = [UIColor blackColor]; 
      subView.delegate = self; 

      NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[book objectAtIndex:i] ofType:@"html" inDirectory:@""]]; 
      [subView loadRequest:[NSURLRequest requestWithURL:url]]; 

      subView.scrollView.bounces = NO; 

      [scrollView addSubview:subView]; 
     } 
     [scrollView setFrame:CGRectMake(0, 0, scrollView.frame.size.width, scrollView.frame.size.height)]; 
     scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * [book count], scrollView.frame.size.height); 

     NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[book objectAtIndex:currentPage] ofType:@"html" inDirectory:@""]]; 
     [[scrollView.subviews objectAtIndex:currentPage] loadRequest:[NSURLRequest requestWithURL:url]]; 

     [scrollView setContentOffset:CGPointMake((scrollView.frame.size.width*currentPage), 0) animated:NO]; 

     subView.scrollView.bounces = NO; 

     [[subView scrollView] setBounces: NO]; 

和HTML代碼

<form name="frm1" method="get" action="p4.html"> 
<div id="question1"> 

<p><b>The phenomenon of a disproportionate traffic development indicates ...</b></p> 

<p><input type="radio" name="question1" value="a1"/><label>An increase of traffic in urban and inner city areas.</label></p> 

<p><input type="radio" name=question1" value="a2"/><label>The need for better and more efficient public, as well as freight transportation.</label></p> 

<p><input type="radio" name="question1" value="a3"/><label>Rising challenges on tackling environmental problems due to increasing traffic.</label></p> 

<p><input type="radio" name="question1" value="a4"/><label>All of the above</label></p> 

<br /> 
<br /> 
</div> 
<div id="next" onclick="Submit()"> </div> 
</form> 

我可以從HTML頁面IOS.I數據只是想表明nslog當我在電臺按鈕觸摸。

回答

0

捕捉使用UIWebView的委託形式行動呼籲和執行JS調用頁面:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{ 
    if ([[[request URL] absoluteString] rangeOfString:@"p4"].location != NSNotFound) { 
     NSLog(@"%@", [self.webView stringByEvaluatingJavaScriptFromString:@"$('input[name=\"question1\"]:checked').val();"]); 
     return NO; 
    } 
}