3

I need <script> in header to define a JavaScript variable (var dates={...};) which is to be used from a .js script.

It should be preferably in header and not inside jQuery(function($){...}) not to hide the variable from using it by my .js script.

Can it be done in any other way than modifying the layout?

4

1 回答 1

2

我通常这样做:

Yii::app()->clientScript->registerScript('my vars','
    var myFirstVar="something";
    var myUrl="' . CController::createUrl("controller/action") . '";
    ,CClientScript::POS_HEAD);
于 2013-07-02T16:12:09.363 回答