简体   繁体   中英

Include JS Files on Yii

I have a question how can i include JS files on Yii, I can not use the default JS or jquery script from Yii.

I have trying to this code-

<link rel="javascript" type="text/javascript" href="<?php echo Yii::app()->request->baseUrl; ?>/js/panel.js" />

Javascript goes in a <script> tag not a <link> tag

Try:

<script src=<?php echo Yii::app()->request->baseUrl; ?>/js/panel.js"></script>

this is what you want:
add this in view file in yii it will add js file after jquery ui

$this->registerJsFile(Yii::$app->request->baseUrl . '/js/yourjs.js', ['depends' => [\frontend\assets\JqueryUiAsset::className()]]);
<?php
$baseUrl = Yii::app()->baseUrl; 
$cs = Yii::app()->getClientScript();
$cs->registerScriptFile($baseUrl.'/js/yourscript.js');
$cs->registerCssFile($baseUrl.'/css/yourcss.css');
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM