在nsstring中获取js复选框标签值

时间:2015-02-17 08:51:18

标签: javascript ios objective-c iphone uiwebview

我已使用以下代码在uiwebview中成功创建了js复选框:

- (void)viewDidLoad {
    [super viewDidLoad];
    //---------------- UITapGesture on UIWebView-----------------------
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(detectTapGesture:)];
    tapGesture.numberOfTapsRequired = 1;
    tapGesture.delegate = self;
    [self.webview addGestureRecognizer:tapGesture];


    array = [[NSMutableArray alloc]initWithObjects:@"'Sudhaadagdudgdada'",@"'qwertyuiopo'",@"'asdfghjkl'", nil];
        NSString *html = [NSString stringWithFormat:@"<div id='check'></div><script> var j; var jsArray = new Array %@; str=''; for(j = 0; j< 3;  j++){ str += '<label><input type=\"radio\" style=\"padding:25px;border-radius:35px;\" id=\"one_'+j+'\" name = \"Sudha\" value = \"'+jsArray[j]+'\" onclick=\"showvalue(this.value);\" />'+jsArray[j]+'</input><br/><br/>'; } document.getElementById(\"check\").innerHTML=str; </script>",array];
    NSLog(@"html..%@",html);

        [self.webview loadHTMLString:html baseURL:nil];

}

现在我想在UIWebView上通过UITapGeture获取nsstring中的复选框onclick值。 我正在尝试此代码,但警告显示正确的值,但没有返回任何内容:

#pragma mark Tap Gesture MEthod
- (void) detectTapGesture:(UITapGestureRecognizer *)gestureRecognizer {

    NSString *result = [self.webview stringByEvaluatingJavaScriptFromString:
                        @"function showvalue(data)  {alert(data);return data;} showvalue(data) "]; //try 2
    NSLog(@"result..%@",result);

}

请帮我在NSString中获取复选框值。是否有其他方法可以从uiwebview获取文本,我已经触摸过或其他任何内容。提前谢谢。

0 个答案:

没有答案
相关问题