registerScript()方法
|
public CClientScript registerScript(string $id, string $script, integer $position=4)
| ||
| $id | string | ID that uniquely identifies this piece of JavaScript code //代码片段的标示字段 |
| $script | string | the javascript code //显示在页面里面的代码 |
| $position | integer | the position of the JavaScript code. Valid values include the following: //加载方式
|
| {return} | CClientScript | the CClientScript object itself (to support method chaining, available since version 1.1.5). |
视图页面加载
Yii::app()->clientScript->registerScript('scriptId', "
var count = 0;
var step = 10;
var speed = 500;
function progress() {
$('#amount').text(count+'%');
$('#progress').progressbar('option', 'value', count);
if(count < 100) {
count = count+step;
setTimeout(progress, speed);
}
}
progress();
", CClientScript::POS_LOAD);显示效果
jQuery(window).load(function() {
var count = 0;
var step = 10;
var speed = 500;
function progress() {
$('#amount').text(count+'%');
$('#progress').progressbar('option', 'value', count);
if(count < 100) {
count = count+step;
setTimeout(progress, speed);
}
}
progress();
});
测试2
Yii::app()->clientScript->registerScript('script_id1','
function test(){
alert("测试内容");
}
test();
',CClientScript::POS_LOAD);
本文详细介绍了Yii框架中CClientScript类的registerScript()方法使用方法。该方法用于注册JavaScript代码,支持不同的加载位置,如页面头部、开始、结束等,并提供了一个示例展示如何在页面加载完成后执行进度条动画。
455

被折叠的 条评论
为什么被折叠?



