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

查看:20
本文介绍了如何在 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 覆盖内置的 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天全站免登陆