gpt4 book ai didi

javascript - 使用包含 .js 和 .css 文件的嵌入式 URL 加载 webview

转载 作者:行者123 更新时间:2023-11-28 12:21:12 27 4
gpt4 key购买 nike

我正在做一个元素,我想在其中以图形显示用户数据..

我想使用 webview、html、javascript 和 css 文件显示图表。

在 webview 中,我得到的是表格而不是图表。

我正在正确获取所有 .js 和 .css 文件的文件路径。

我已经在副本 Bundle Resources 中复制了 .js 和 .css 文件。

这是我的代码

NSURL* path = [[NSBundle mainBundle] URLForResource:@"jquery.min" withExtension:@"js"];
NSLog(@"PATH %@",path);
NSURL* path1 = [[NSBundle mainBundle] URLForResource:@"03" withExtension:@"js"];
NSLog(@"PATH %@",path1);

NSURL* css1path = [[NSBundle mainBundle] URLForResource:@"common" withExtension:@"css"];

NSLog(@"CSSPATH %@",css1path);

NSURL* css2path = [[NSBundle mainBundle] URLForResource:@"03" withExtension:@"css"];
NSLog(@"CSS2PATH %@",css2path);




NSString *str = @"<html lang=\"en\">";
str=[str stringByAppendingString:@"<head>"];
str=[str stringByAppendingString:@"<meta charset=\"utf-8\">"];
str=[str stringByAppendingString:@"<meta name=\"viewport\" content=\"width=800\">"];
str=[str stringByAppendingString:@"<title>Sleep Hour Graph of myBeats</title>"];
str=[str stringByAppendingFormat:@"<link rel=\"stylesheet\" href=%@\">",css1path];
str=[str stringByAppendingFormat:@"<link rel=\"stylesheet\" href=%@\">",css2path];
str=[str stringByAppendingString:@"</head>"];

str=[str stringByAppendingString:@"<body>"];

str=[str stringByAppendingString:@"<div id=\"wrapper\">"];

str=[str stringByAppendingString:@"<div class=\"chart\">"];

str=[str stringByAppendingString:@"<h2>Weekly Sleep Graph/Hour</h2>"];

str=[str stringByAppendingString:@"<table id=\"data-table\" border=\"1\" cellpadding=\"10\" cellspacing=\"0\" summary=\"Sleep hours from 2013-08-12 to 2013-08-18\">"];
str=[str stringByAppendingString:@"<caption>Sleep in Hours</caption>"];
str=[str stringByAppendingString:@"<thead>"];
str=[str stringByAppendingString:@"<tr>"];
str=[str stringByAppendingString:@"<td>&nbsp;</td>"];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str1];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str2];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str3];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str4];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str5];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str6];
str=[str stringByAppendingFormat:@"<th scope=\"col\">%@</th>",Str7];
str=[str stringByAppendingString:@"</tr>"];
str=[str stringByAppendingString:@"</thead>"];
str=[str stringByAppendingString:@"<tbody>"];
str=[str stringByAppendingString:@"<tr>"];
str=[str stringByAppendingString:@"<th scope=\"row\">Sleep in Hours Per Day</th>"];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str11];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str22];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str33];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str44];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str55];
str=[str stringByAppendingFormat:@"<td>%@</td>",str66];
str=[str stringByAppendingFormat:@"<td>%@</td>",Str77];
str=[str stringByAppendingString:@"</tr>"];
str=[str stringByAppendingString:@"</tbody>"];
str=[str stringByAppendingString:@"</table>"];

str=[str stringByAppendingString:@"</div>"];

str=[str stringByAppendingString:@"</div>"];

str=[str stringByAppendingFormat:@"<script type=\"text/javascript\" src=%@\"></script>",path];

str=[str stringByAppendingFormat:@"<script type=\"text/javascript\" src=%@\"></script>",path1];

str=[str stringByAppendingString:@"</body>"];

str=[str stringByAppendingString:@"</html>"];
NSLog(@"HTMLFINAL %@",str);
[webview loadHTMLString:str baseURL:nil];

[webview stringByEvaluatingJavaScriptFromString:str];

我得到的输出:

enter image description here

期望的输出:

enter image description here

最佳答案

您的 hrefsrc 属性缺少前导 \"

str=[str stringByAppendingFormat:@"<link rel=\"stylesheet\" href=%@\">",css1path];
^

关于javascript - 使用包含 .js 和 .css 文件的嵌入式 URL 加载 webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18849969/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com