BUG YII2.0 $ is not defined
来源:https://www.cnblogs.com/attitudeY/p/6279985.html
BUG描述:$ is not defined 没有加载jquery成功
原因:Yii2.0将JS代码默认加载页面加载后
解决方案:
第一种方案:最简单方法是在 assets\AppAsset.php 中加上,页面前加载
public $jsOptions = array(
'position' => \yii\web\View::POS_HEAD
);
第二种方案:But in production you usually want the scripts to load last, and instead you let Yii2 handle your javascript:
$this->registerJs(
'$("document").ready(function(){ alert("hi"); });'
);
Now Yii will handle this js and place it after anything important (like jQuery).
You'll however soon notice that IDE's are usually bad at handling this kind of language nesting (JavaScript inside PHP) so the syntax highlighting is likely to break. One way to solve it is to register your script in a separate file:
$this->registerJsFile( 'myScript.js' );
If you want even more control about which order to load your scripts, you can add dependencies as your second argument, and additional options as the third:
$this->registerJsFile(
'myScript.js',
['\backend\assets\AppAsset'],
['position' => '\yii\web\View::POS_END']
);
If you for some reason absolutely want the script to be rendered inline you can do:
$this->registerJs( $this->renderPartial('myScript.js') );
The recommended way to add your scripts is to use AssetBundles. Look in assets/AppAssets.php and add your js-file to the $js-array.
BUG YII2.0 $ is not defined的更多相关文章
- Yii2.0
Yii2.0基础框架 缘起 因为一个月的短暂停留,我在给朋友搞事情,所以Yii系列的文章耽搁了很长时间,现在又重拾当时的知识,给大伙好好撸下这一系列的博客 提起Yii,虽然是国外的开发者搞的,但是 ...
- 【转】PHP框架性能测试报告 - ThinkPHP 3.2.3 Laravel 5.2 Yii2.0.5
作为一个PHP开发者,而且是初创企业团队的技术开发者,选择开发框架是个很艰难的事情. 用ThinkPHP的话,招聘一个刚从培训机构出来的开发者就可以上手了,但是性能和后期代码解耦是个让人头疼的事情.不 ...
- 在beforeAction里redirect无效,Yii2.0.8
我是在官方GitHub上得到回答,试了一下,确实解决问题了.之前的问题描述: 之前是2.0.3,然后用composer直接升级到2.0.8,就不正常了,以为是我代码的问题,于是再次尝试 用compos ...
- 关于在Windows下Composer下载安装Yii2.0
先是composer的安装,主要有两个方式,一个直接下载安装包安装,Composer-steup.exe文件,第二种直接下载composer.phar文件,用php去运行这个文件可以一样起到作用,之后 ...
- Yii1.1应用升级到Yii2.0的一些注意点
1. 应用程序实例直接使用全局命名变量来訪问:$app,而无须调用app() 2. Yii2在视图层的一个显著改变是引入了视图类,这样在MVC模式实现上更为完整. 对应的,相关展现层附属类就由新的视图 ...
- BUG YII2.0 cURL error 6: Could not resolve host:
BUG描述:登录直接显示 原因:服务器设置端口权限,或者DNS毛病 解决方案:只能去服务器端设置,配置端口 DNS: 修改dns 114.114.114.114 或者 8.8.8.8
- 学习yii2.0——行为
学习yii框架的行为之前,需要先了解yii的事件,可以参考这篇博客: 怎么理解行为 yii框架的行为有点类似于trait,可以有个大体的概念: 1.有一个类A,包含一些属性和方法,很普通的一个类A. ...
- MacBook Pro 安装composer及Yii2.0
最近想看看Yii的一些东西,需要安装一下composer curl -sS https://getcomposer.org/installer | php 此操作会下载最新版本到当前的目录下 然后将下 ...
- yii2——自定义widget
参考资料:http://www.bsourcecode.com/yiiframework2/how-to-create-custom-widget-in-yii2-0-framework/ 如何使 ...
随机推荐
- 微信小程序开发——全局配置详细介绍
本文针对官方文档未说明清楚的进行详细探索研究,官方文档详见:全局配置 . pages: 删除页面,需要先删除app.json中pages对应页面的路径,再去删除页面相关的所有文件,不然会出现页面文件混 ...
- Intellij创建简单Springboot项目
Intellij创建简单Springboot项目 第一步:选择创建新项目——file-new-project 第二步:选择项目类型——Spring Initializr-next 第三步:输入项目信息 ...
- 解决自定义classloader后无法使用maven install
@上篇博客中探讨了web项目利用自定义classloader进行解密,利用的是编译后的文件直接运行程序一切正常 今天博主在探讨加密后进行混淆时,打包程序报程序包org.apache.catalina. ...
- Ubuntu防火墙配置
转载自:http://blog.csdn.net/sumer0922/article/details/7485584Ubuntu11.04默认的是UFW(ufw 即uncomplicated fire ...
- golang 常用的正则查找与替换
package main; import ( "regexp" "fmt" "strings" ) func main() { //1.过正 ...
- TouchSlide 插件使用介绍
TouchSlide(PC端插件http://www.superslide2.com/demo.html#effect1) 可用于javascript触屏滑动特效插件,移动端滑动特效,触屏焦点图,触屏 ...
- Vue 初始化多个Vue 及之间的相互修改
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- BOM DOM jQuery
. BOM . location相关 . location.href . location.href="http://www.sogo.com" . location.reload ...
- Java并发-UncaughtExceptionHandler捕获线程异常信息并重新启动线程
Java并发-UncaughtExceptionHandler捕获线程异常信息并重新启动线程 一.捕获异常并重新启用线程 public class Testun { public static voi ...
- 【转】我为什么把think in java 读了10遍
我在想写这篇博文之前,就曾经对我媳妇(她是做web前端的)讲,我把think in java看了几次几次,媳妇那时就用很羡慕和莫名的眼神看着我说,你真有毅力,我当时就蒙了,我以为她会说,你现在基础一定 ...