Javascript jquery ui - 如何使用谷歌 CDN

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5206666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 16:10:45  来源:igfitidea点击:

jquery ui - how to use google CDN

javascriptjqueryjquery-uicdngoogle-cdn

提问by raklos

I want to use Google CDN for jQuery and jQuery UI..

我想将 Google CDN 用于 jQuery 和 jQuery UI ..

I'm using the answer from here for jQuery. Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail

我将这里的答案用于 jQuery。 使用 Google 托管的 jQuery 的最佳方法,但退回到我在 Google 上的托管库失败

but i don't understand this bit:

但我不明白这一点:

if (typeof jQuery == 'undefined')

so how can i do it for jQuery UI? also, will this work with custom jQuery UI theme as this produces a custom js file too?

那么我该如何为 jQuery UI 做到这一点呢?此外,这是否适用于自定义 jQuery UI 主题,因为这也会生成自定义 js 文件?

回答by Hussein

You can make the call using

您可以使用

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" /> 
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>

You can also link to other Ui themes by changes the name of the theme. In This case change the name base to any other theme name /base/jquery-ui.cssto any other theme.

您还可以通过更改主题名称链接到其他 Ui 主题。在这种情况下,将名称基础更改为任何其他主题名称/base/jquery-ui.css到任何其他主题。

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" />

Check out the jQuery UI Blog for a link of all CDN links http://blog.jqueryui.com/

查看 jQuery UI 博客以获取所有 CDN 链接的链接http://blog.jqueryui.com/

If you're concerned that the Google CDN ever fails or goes down, you can fall back to a local copy when the CDN is offline (this example is baked into templates like HTML5 Boilerplate):

如果您担心 Google CDN 会出现故障或宕机,您可以在 CDN 离线时回退到本地副本(此示例已融入 HTML5 Boilerplate 等模板中):

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
    window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"></script>')
</script>

回答by JasCav

If you are having a custom jQuery UI theme, you have to host that on your own server. Google only hosts the main jQuery UI themes.

如果您有自定义 jQuery UI 主题,则必须将其托管在您自己的服务器上。Google 只托管主要的 jQuery UI 主题

If you want to check whether or not the jQuery UI library has loaded, you can do this:

如果要检查 jQuery UI 库是否已加载,可以执行以下操作:

if (jQuery.ui) {
}

回答by Syed Priom

Here is the list, just change to the version you need.

这是列表,只需更改为您需要的版本即可。

https://developers.google.com/speed/libraries/devguide#jquery-ui

https://developers.google.com/speed/libraries/devguide#jquery-ui