在视图中引入js的问题 [ 求助交流 ]
在yii2 advanced版的frontend中的视图引入CDN上的js文件,然而却报错了 代码如下
<?php
use yii\helpers\Html;
use yii\helpers\Url;
$this->title = '表格';
$this->params['breadcrumbs'][] = ['label' => 'Tool', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<html>
<head>
<?php $this->registerJsFile("http://cdn.hcharts.cn/jquery/jquery-1.8.3.min.js") ?>
<?php $this->registerJsFile("http://cdn.hcharts.cn/highcharts/highcharts.js") ?>
<script>
$(function () {
$('#container').highcharts({
chart: {
type: 'area'
},
title: {
text: 'skyline traveler '
},
xAxis: {
categories: ['a', 'b', 'c']
},
yAxis: {
title: {
text: 'sss'
}
},
series: [{
name: 'hhh',
data: [1, 0, 4, 0]
}, {
name: 'kkk',
data: [2, 59, 3, 0]
}, {
name: 'kkk',
data: [3, 71, 3, 0]
}, {
name: 'kkk',
data: [4, 12, 3, 0]
}, {
name: 'kkk',
data: [5, 27, 3, 0]
}, {
name: 'kkk',
data: [25, 17, 3, 0]
}, {
name: 'kkk',
data: [35, 27, 3, 0]
}, {
name: 'kkk',
data: [75, 7, 3, 0]
}]
});
});
</script>
</head>
<body>
<div id="container" style="min-width: 720px;height: 540px"></div>
</body>
</html>
用的是highcharts的,在单独的php文件中写入就没有问题,然而在框架中却不显示并且报错 "charts:46 Uncaught ReferenceError: $ is not defined" 请大神指教!
共 4 条回复
-
谢谢两位解答,然而还是报错:
PHP Warning – yii\base\ErrorException Cannot use a scalar value as an array 1. in E:\www\yii2test\vendor\yiisoft\yii2\helpers\BaseHtml.php at line 261 * * The rest of the options will be rendered as the attributes of the resulting script tag. The values will * be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. * See [[renderTagAttributes()]] for details on how attributes are being rendered. * @return string the generated script tag * @see Url::to() */ public static function jsFile($url, $options = []) { $options['src'] = Url::to($url); if (isset($options['condition'])) { $condition = $options['condition']; unset($options['condition']); return self::wrapIntoCondition(static::tag('script', '', $options), $condition); } else { return static::tag('script', '', $options); } }
hebo5485
注册时间:2016-03-18
最后登录:2024-04-05
在线时长:66小时28分
最后登录:2024-04-05
在线时长:66小时28分
- 粉丝8
- 金钱4600
- 威望30
- 积分5560