JavaScript queryselector方法在IE8中不起作用

时间:2015-05-11 06:54:10

标签: javascript html ie8-compatibility-mode

以下代码在Chrome中有效但在IE中无效

NSDictionary *products=[jSONData valueForKey:@"products"];
NSDictionary *product=[products valueForKey:@"product"];
NSString *name=[product objectForKey:@"name"]; 

在try catch块中抛出无效参数的错误 请建议解决方案

2 个答案:

答案 0 :(得分:3)

我认为问题是:checked selector,即not supported in IE8

  NSString *oauthParameters = authHeaders[@"X-Verify-Credentials-Authorization"];
                         NSString *urlString = authHeaders[@"X-Auth-Service-Provider"];
                         NSMutableURLRequest *request =
                         [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
                         request.allHTTPHeaderFields = @{@"Authorization":oauthParameters};
                         [request setHTTPMethod:@"GET"];
                         NSOperationQueue *queue = [[NSOperationQueue alloc]init];
                         [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response,NSData *data,NSError *error){
                              NSDictionary *twitterData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:NULL];
                         }];

答案 1 :(得分:0)

IE8中的document.querySelector只识别CSS 2.1选择器和非特殊标签(html5标签,如section或article)。 为了避免这种情况,你可以使用像jQuery这样的库:http://jquery.com/