A-A+

Yii中对Js的操作控制

2013年03月22日 JavaScript, YIIFramework 暂无评论 阅读 4,457 次

//如何在控制器添加CSS文件或JavaScript文件

Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/my.css');  
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/css/my.js');  
<?php echo$this->module->assetsUrl; ?>/css/main.css  
Yii::app()->clientScript->registerCoreScript('jquery');

//插入meta信息

Yii::app()->clientScript->registerMetaTag('keywords','关键字');  
Yii::app()->clientScript->registerMetaTag('description','一些描述');  
Yii::app()->clientScript->registerMetaTag('author','作者');

//其他用法

//注册JS代码: 
$cs = Yii::app()->getClientScript(); 
//注册JS文件 
$cs->registerScriptFile('js/amcharts/javascript/amcharts.js', CClientScript::POS_HEAD);    
$cs->registerScriptFile('js/amcharts/javascript/raphael.js', CClientScript::POS_HEAD); 

//将php的数组转化为javascript
$joptions=CJavaScript::encode($this->options);

//注册JS代码 
$cs->registerScript('f1','var chart;');    
$cs->registerScript('f2','var newValueAxis;');    
$cs->registerScript('f3','var addAxis;');    
$cs->registerScript('f4','var removeAxis;');    
$cs->registerScript('f5','chart = new AmCharts.AmSerialChart();');    
$cs->registerScript('f6','chart.pathToImages = "images/amcharts/";');    
$cs->registerScript('f7','chart.addListener("dataUpdated");');    
$cs->registerScript('f9','chart.marginLeft = 80;'); 
$cs->registerScript('f10','chart.marginRight = 50;');    
标签:

给我留言