这里是我的代码:我得到了一个空白页面,当我尝试Java脚本加载到网络视图
- (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>
的script.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文件的内容。我做对了吗?
您是否试图在桌面浏览器中加载此代码?怎么了? – Jim 2012-07-31 20:20:01
首先将'alert('Done。');'添加到'script.js'的底部。它是否在设备上运行?也许把它移到'
'。接下来,除了'$('#button')之外的所有东西都是空的'script.js'。click(function(){alert('clicked');});'当按钮被点击/点击时,这会被触发吗?然后你可以尝试'.on('click',...)'和next,尽管我不认为点击注册为'tap'尝试'.on('tap',...)'。再多一些想法。 – 2012-08-01 00:49:58