2013-12-09 28 views
0

我在主題/引導/視圖/佈局上添加該代碼/ main.php警予registerScriptFile不起作用

Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/custom.js'); 
在我的HTML

它只表示

<head> 
    <script type="text/javascript" src="/dev2/js/custom.js"></script> 
</head> 

,並在custom.js文件我有這個

jQuery(function($) { 
    alert('test'); 
} 

當頁負載,我沒有得到任何警報顯示。該文件確實存在於正確的目錄中,我沒有得到螢火蟲警告。由於某些原因,我手動使用registerScriptFile包含的所有JS文件都不起作用。我的插件中沒有包含任何工作。有任何想法嗎?

回答

0

你可以試試這個:

$(document).ready(function(){ 
alert('hello'); 
// Enter code here 
}); 
在custom.js

0
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/custom', CClientScript::POS_HEAD); 

和錯誤的腳本:

jQuery(function($) { 
    alert('test'); 
}); 

有工作