我想改变jquery在我的yii应用程序,使用jquery 1.9而不是使用jquery从yii。
但是我发现一些方法被弃用了,比如jquery-ba-bbq.js和main.js中的$.browser()和$.live()
我的问题:1. 如何删除这两个js,因为它们是由yii应用程序自动加载的。我应该使用哪个配置文件。2. 我应该用modernzr lib代替吗?
提前致谢
关于你的第一个问题,在配置文件中使用clientScript
scriptMap
选项:
...
'clientScript' => array(
'scriptMap' => array(
'jquery.min.js' => 'your URL or Google CDN link',
),
),
...
你也可以使用升级后的库来兼容jQuery。如果你确实修复了兼容性错误,请在你的更新中发送一些拉请求,以便主jQuery库也可以更新:-)
'clientScript'=>array(
'packages'=>array(
'jquery'=>array(
'baseUrl'=> 'siteasset/jquery' ,
'js'=>array('jquery-1.10.2.min.js','jquery.browser.js'),
// you can also add css files
'css'=>array('css file path')
)
),
),
把它放在config文件夹下的main.php文件中…在main.php下的组件....然后在controller.php的components文件夹下注册你的包。你的控制器。php应该像这样
<?php
class Controller extends CController
{
/**
* @var string the default layout for the controller view. Defaults to '//layouts/column1',
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
*/
public $layout='//layouts/content';
/**
* @var array context menu items. This property will be assigned to {@link CMenu::items}.
*/
public $menu=array();
/**
* @var array the breadcrumbs of the current page. The value of this property will
* be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
* for more details on how to specify this property.
*/
public $breadcrumbs=array();
public function beforeAction($action) {
$cs = Yii::app()->clientScript;
$url = Yii::app()->baseUrl;
if(Yii::app()->request->isAjaxRequest)
{
}
else
{
$cs->registerPackage('jquery');
// here you can also register your another css
// and js file .. this code will be
// executed every time before an action
// is called via ajax or in normal way..
//another thing here you can also controll
//in which type of request which scipts
// shiould be generated again..
//here you can see i am not sending
//any js /css files if there is ajax request
}
return parent::beforeAction($action);
}
}
通过这个你可以改变你的js/css文件来自你的默认Yii框架....
我还想包括jquery1.7和更高版本…没有jquery.browser.js不包括在内,所以你必须单独下载它并独立附加它。jquery.browser.js