2015-02-16 4 views
0

Я пытаюсь создать динамический флажок в UIWebView. Я использую этот код:Создать динамический флажок в UIWebView

NSMutableArray *array = [[NSMutableArray alloc]initWithObjects:@"Sudhaadagdudgdada",@"qwertyuiopo",@"asdfghjkl", nil]; 

    for (int j = 0; j < array.count; j++) 
    { 
     NSString *html = [NSString stringWithFormat:@"<div id='check'></div><script> str=''; str += '<input type=\"checkbox\" name=\"one_'+i+'\" value=\"'+%@+'\" onclick=alert(this.value); />' document.getElementById(\"check\").innerHTML=str;</script>",[array objectAtIndex:j]]; 

     [self.webview loadHTMLString:[NSString stringWithFormat:@"%@",html] baseURL:nil]; 

    } 

Но в UIWebView отсутствует флажок. Пожалуйста, помогите мне.

ответ

0

я решил этим:

NSMutableArray *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 += '<input type=\"checkbox\" name=\"one_'+j+'\" value = \"'+jsArray[j]+'\" onclick=\"alert(this.value);\" />'+jsArray[j]+'<br/><br/>'; } document.getElementById(\"check\").innerHTML=str;</script>",array]; 
    NSLog(@"html..%@",html); 

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

Если и хочет загрузить HTML в WebView и нужно добавить тег для it.Update ур кода, как показано ниже

NSString *html = [NSString stringWithFormat:@"<html><head><div id='check'></div><script> str=''; str += '<input type=\"checkbox\" name=\"one_'+i+'\" value=\"'+%@+'\" onclick=alert(this.value); />' document.getElementById(\"check\").innerHTML=str;</script></head></html>",[array objectAtIndex:j]]; 

// ИЛИ Если и хотят, чтобы загрузить файл яваскрипт, как у упомянутых в коде .. изменения, как показано ниже

NSMutableArray *array = [[NSMutableArray alloc]initWithObjects:@"Sudhaadagdudgdada",@"qwertyuiopo",@"asdfghjkl", nil]; 

    for (int j = 0; j < array.count; j++) 
    { 
     NSString *html = [NSString stringWithFormat:@"<div id='check'></div><script> str=''; str += '<input type=\"checkbox\" name=\"one_'+i+'\" value=\"'+%@+'\" onclick=alert(this.value); />' document.getElementById(\"check\").innerHTML=str;</script>",[array objectAtIndex:j]]; 

     [webView stringByEvaluatingJavaScriptFromString: 
     [NSString stringWithFormat:@"%@",html]]; 

    } 

Надеется, что это помогает ...

+0

спасибо за ответ ур. Но это не работает. – Sudha

+0

по-прежнему пустой uiwebview :( – Sudha