gpt4 book ai didi

javascript - Yii::app()->clientScript->registerCoreScript ('jquery' );

转载 作者:行者123 更新时间:2023-12-03 10:05:09 24 4
gpt4 key购买 nike

我正在使用

<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>

用于在 Yii 1 脚本顶部但在页面中注册 jquery添加了最后一个脚本?为什么?

最佳答案

您可以使用coreScriptPosition来实现此目的。

直接来自docs :

Where the scripts registered using registerCoreScript or registerPackage will be inserted in the page. This can be one of the CClientScript::POS_* constants. Defaults to CClientScript::POS_HEAD.

像这样使用:

$cs = Yii::app()->clientScript;
$cs->coreScriptPosition = CClientScript::POS_HEAD;
$cs->registerCoreScript('jquery');

另一个有用的link阅读此内容。 (也请阅读评论)

--编辑--

您可以告诉 Yii 将脚本放在方法中的位置:

Yii::app()->clientScript->registerScript(string $id, string $script, integer $position=NULL, array $htmlOptions=array ( ));

$position 变量将是脚本在页面上的位置。

可以是以下任何一个:

  • CClientScript::POS_HEAD :脚本插入到标题元素之前的 head 部分中。
  • CClientScript::POS_BEGIN :脚本插入到正文部分的开头。
  • CClientScript::POS_END :脚本插入到正文部分的末尾。
  • CClientScript::POS_LOAD :脚本插入到 window.onload() 函数中。
  • CClientScript::POS_READY :脚本插入到 jQuery 的 Ready 函数中。

关于javascript - Yii::app()->clientScript->registerCoreScript ('jquery' );,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30392503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com