如何在视图文件中由 Datepicker 小部件生成的 javascript 代码之后包含我的 .js 文件。
echo DatePicker::widget([
'name' => 'datepicker--2',
'id' => 'datepicker--2',
'clientOptions' => [
'showOtherMonths' => true,
'maxDate' => '+ 0d',
'showOtherMonths' => true,
'selectOtherMonths' => true,
]
]);
我的资产包:
namespace app\assets;
use yii\web\AssetBundle;
class ChartsAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $js = [
'js/charts.js',
'js/charts-init.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\jui\JuiAsset',
'yii\web\JqueryAsset',
];
}
我在我的页面源上得到了什么:
...
<script src="/new/js/charts.js"></script>
<script src="/new/js/charts-init.js"></script>
<script type="text/javascript">jQuery(document).ready(function () {
$('#datepicker--2').datepicker($.extend({}, {"showOtherMonths":true,"maxDate":"+ 0d","selectOtherMonths":true,"dateFormat":"M d, yy"}));
});</script></body>
</html>