如何在Yii框架中使用jQuery? [英] How to use jQuery with the Yii framework.?

查看:85
本文介绍了如何在Yii框架中使用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在yii中使用jquery/javascript?,

How to use jquery/javascript in yii?,

如何在yii中使用我的脚本?

How to use my Script in yii?

为什么这与以其他任何方式使用jQuery有什么不同?

Why is this any different from using jQuery in any other way?

推荐答案

如何在yii中使用jquery?

How to use jquery in yii?

如上所述,您可以注册一个新的脚本块,也可以注册一个新的外部脚本文件.您还可以在插件中注册资产,这些资产将占用整个JS文件夹并将其合并到您的应用中.

As you stated above you can either register a new script block or you can register a new external script file. You cna also register assets within plugins which will take entire JS folders and combine them into your app.

因此,有很多在Yii中使用JQuery的方法.

So there are many ways to use JQuery in Yii.

如何在yii中使用我的jquery

How to use my jquery in yii

JQuery随JQuery预先捆绑和激活,并且JQuery库本身被认为是核心脚本,因此并不需要真正放入您自己的JQuery.

JQuery comes pre-bundled and activated with JQuery and the JQuery library itself is considered a core script so there is no real need to put your own JQuery in.

您可以输入以下内容来覆盖内置的JQuery:

You can overwrite the built in JQuery with your own by putting:

$cs = Yii::app()->clientScript;
$cs->scriptMap = array(
'jquery.js' => Yii::app()->request->baseUrl.'/js/jquery.js',
'jquery.yii.js' => Yii::app()->request->baseUrl.'/js/jquery.min.js',
);
$cs->registerCoreScript('jquery');
$cs->registerCoreScript('jquery.ui');

在您的布局,操作或视图中的某处类似的内容.我更喜欢将其放置在布局中,并亲自管理自己的JQuery版本.

Something like that somewhere within either your layout, action or view. I prefer to put this within the layout and manage my own JQuery version personally.

为什么这与以其他任何方式使用jQuery有什么不同?

Why is this any different from using jQuery in any other way?

主要是由于框架及其组件的标准化和互操作性.总体上预捆绑了用于JQuery UI小部件和JQuery元素的内置钩子,使该框架更容易构建可重用和干净的JS对象,以供您在应用程序中使用.

Mainly due to standardisation and interoperability of the framework and its components. Coming pre-bundled with built in hooks for JQuery UI widgets and JQuery elements in general makes the framework much easier to build reusable and clean JS objects for use in your app.

我也喜欢JQuery,所以在我看来,将其预捆绑是有道理的.但是,这并不是让JQuery成为唯一的JS库/框架,因此并不能招揽兵,您应该真正考虑哪种才是最适合自己的选择.

Also I like JQuery so it makes sense for it to come pre-bundled in my opinion. However this is not a call to arms for JQuery being the only JS library/framework out there and you should really consider which is best for you before you choose.

这篇关于如何在Yii框架中使用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆