zoukankan      html  css  js  c++  java
  • yii2引入js和css

    assets/AppAsset.php

    public $css = [
        'css/site.css',
        'css/font/css/font-awesome.min.css',
        'css/doc.css',
    ];
    public $js = [
        'js/core/app.js',
    ];
    布局文件中有
    AppAsset::register($this);

    http://www.yiichina.com/question/344

    http://www.yiichina.com/topic/5604

    //输出url

    <a href="<?=  Url::to(['/users/login/login','id'=>5,'mark'=>true]) ?>" >登录 </a>

    以上等同于

    <a href="/users/login/login?id=5&mark=true" >登录 </a>

    //注册css

    ①css代码

    <?php

      $css=<<<CSS

      .title{

        color:blue;

        }

      CSS;

    $this->registerCss($css,View::POS_END);  //注册css代码 ,并置于最后面,避免被覆盖

    ?>

    ②注册css样式文件

    <?php

      $this->registerCssFile('@web/css/mystyle.css');

    ?>

    //注册js

    ①js代码

    <?php

       $js=<<<JS

      alert(123);

      JS;

      $this->registerJs($js,View::POS_HEAD); //注册JS代码 ,并置于最前面

      ?>

    ② js文件

    <?php

      $this->registerJsFile('@web/js/myJs.js')

      ?>

    参考:http://www.cnblogs.com/sheapchen/p/3939767.html

    解决引入顺序:

    use appassetsAppAsset;
    use yiiootstrapBootstrapAsset;

    AppAsset::register($this);

    $this->registerCssFile("@web/css/login.css",[
    'depends'=>[BootstrapAsset::className()]
    ]);

    关键是depends,参考:http://www.yiiframework.com/doc-2.0/guide-output-client-scripts.html

    The option depends is specially handled. It specifies which asset bundles this CSS file depends on. In this case, the dependent asset bundle is BootstrapAsset. This means the CSS file will be added afterthe CSS files in BootstrapAsset.

  • 相关阅读:
    虚拟化碎片知识
    CentOS升级内核及KVM安装(已试验,可行)
    Libvirt 虚拟化库剖析
    [ACM]Max Sum
    [ACM]n a^o7 !
    [java]ActionEvent事件:获取输入字符串的长度
    [ACM]The Best Seat in ACM Contest
    [java]ItemEvent事件:简单计算器
    通过注册表的句柄得到当前句柄在注册表中的路径
    [测试模式]Setup方法的滥用
  • 原文地址:https://www.cnblogs.com/youxin/p/4495119.html
Copyright © 2011-2022 走看看