这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSError *error;
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
NSLog(@"%@", html);
[webview loadHTMLString:html baseURL:baseURL];
NSLog(@"error: %@", error);
}
这是html的内容:
<html>
<head>
<script src="jquerymin.js"></script>
<script src="highcharts.js"></script>
<script src="exporting.js"></script>
</head>
<body>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
<script src="script.js"></script>
Test
<input type="button" id="button" />
</body>
</html>
脚本.js:
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Therapist productivity by Region'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
}
}
},
series: [{
type: 'pie',
name: 'Therapist Productivity',
data: [
['South Carolina', 45.0],
['Michigan', 26.8],
{
name: 'California',
y: 12.8,
sliced: true,
selected: true
},
['Florida', 8.5],
['New York', 6.2],
['Maine', 0.7]
]
}]
});
});
});
$('#button').click(function() {
$(chart.container).hide();
chart.series[0].remove();
$(chart.container).show();
});
当我运行我的代码时,来自 HTML 和“测试”的按钮会显示在屏幕上,但不会显示正在加载的 .js 文件的内容。我这样做对吗?