Yii框架在脚本标记

时间:2017-04-11 07:56:06

标签: javascript php jquery yii

如何在脚本标记中添加延迟?我使用此Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl().'/js/jquery.js');

我尝试更改为Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl().'/js/jquery.js', CClientScript::POS_HEAD,array('defer'=>'defer'));

Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl().'/js/jquery.js', CClientScript::POS_HEAD,array('id'=>'defer'));

不起作用。我不知道该怎么做。请帮忙。

2 个答案:

答案 0 :(得分:0)

我发现了这种方式:

  1. 检查 CClientScript.php 中的函数registerScriptFile(),如果param htmlOptions 不存在,则替换下面的2个文件来自https://github.com/yiisoft/yii

    的来源
  2. 文件中功能'defer'=>1的注释行renderAttributes() CHtml.php
  3. 添加此行: Yii :: app() - > clientScript-> registerScriptFile(Yii :: app() - > get BaseUrl()。'/ js / jquer y.js',CClientScript :: POS_HEAD,array('defer '=>''));

答案 1 :(得分:0)

您可以提供

之类的选项。
$this->registerJsFile('https://apis.google.com/js/platform.js?onload=renderButton',['position' => View::POS_END, 'async'=>true, 'defer'=>true]);

要添加内部js

  $this->registerJsFile(Yii::$app->view->theme->baseUrl .'/your_js_path',['position' => View::POS_END, 'async'=>true, 'defer'=>true]);