1. 视图页面直接加载
$css = <<<CSS
p {text-indent:5em;}
div{width: 500px;}
CSS;
$this->registerCss($css,['type'=>'text/css'],'test');
$js = <<<JS
// console.log('sss');
JS;
$this->registerJs($js);
2. 视图页面直接加载css,js文件
$this->registerJsFile('@web/assets/9d00e06a/core.js');
$this->registerCssFile('@web/assets/9d00e06a/core.js');
<script type="text/javascript">
<?php $this->beginBlock('JS_END') ?>
function check(item){
var id = $(item).attr("data-id");
$('.extra').hide();
$.ajax({
type: "POST",
url: "<?=Url::to(['admin/info-view'])?>",
dataType: 'JSON',
data: {'id':id},
success: function (data) {
if(data.error==0){
$('#alertModal').modal();
$('#alertModalLabel').html(data.content.title);
$('#alert-message').html(data.content.content);
// $('#alertModalsubhead').html(' 浏览量:'+json.data.count+' ');
// if(json.data.file > 0){
// $('.extra').attr('href',json.data.extra).show();
// }
}else{
MXHY.msg('请求出错','error');
}
}
});
}
function addhtml(data,dom){
var html = '';
var info='';
for (var i = 0; i < data.length; i++) {
if(data[i].recommend==2){
info = 'info-e';
}else{
info='';
}
html += "<tr><td width='80%' style='line-height:30px;'><a class='info_d "+info+"' onclick='check(this)' data-id='"+data[i].id+"'>"+data[i].title+"</a></td><td width='20%' style='line-height:30px;text-align:center;'>"+data[i].create_time+"</td></tr>";
}
dom.html(html);
}
<?php
$infoType = Yii::$app->params['INFO_TYPE'];
foreach($infoType as $k=>$type){
?>
$("#page-ann<?=$k?>").pagination({
totalData: <?=$typeTotal[$k]?>,
showData: 10,
coping: true,
homePage: '首页',
endPage: '末页',
count: 1,
callback:function(api){
var data = {
page: api.getCurrent(),
type: <?=$k?>,
};
$.post('<?=Url::to(['info-page'])?>',data,function(data){
if(data.error==0){
addhtml(data.content,$('.ann<?=$k?>'));
}else{
MXHY.msg('请求出错','error');
}
});
}
});
<?php
}
?>
<?php $this->endBlock(); ?>
</script>
<?php $this->registerJs($this->blocks['JS_END'], yii\web\View::POS_END); ?>
<?php
$this->registerCssFile('@web/js/libs/pagination/style/pagination.css',[
'depends'=>'backend\assets\AppAsset'
]);
$this->registerJsFile('@web/js/libs/pagination/script/jquery.pagination.js',[
'depends'=>'backend\assets\AppAsset'
])
?>
https://blog.csdn.net/maclechan/article/details/45803821