简体   繁体   English

为什么我的jQuery UI CSS无法在JSFiddle中运行?

[英]Why is my jQuery UI CSS not working in JSFiddle?

For answering questions with JavaScript input i often use Demos on JSFiddle . 对于使用JavaScript输入回答问题,我经常在JSFiddle上使用Demos。 It is very useful, but when i was answering this tooltip question i needed the usage of jQuery UI . 它非常有用,但当我回答这个工具提示问题时,我需要使用jQuery UI

The problem of this usage is, that you can check the jQuery UI in the Framework selection, but it loads only the js file and not the css files. 这种用法的问题是,您可以在Framework选择中检查jQuery UI,但它只加载js文件而不加载css文件。

So i decided to link to this http://jqueryui.com/themes/base/jquery.ui.all.css used in the official Demos of jQuery UI. 所以我决定链接到jQuery UI官方演示中使用的http://jqueryui.com/themes/base/jquery.ui.all.css => Problem solved. =>问题解决了。

Really solved? 真的解决了? No?! 没有?!

Because this link works great if a user has opened a jQuery Demo before, but as i did see here at my work it doesn't work if I only open the fiddle without ever having open one demo. 因为如果用户之前已经打开过jQuery Demo,这个链接效果很好,但正如我在我的工作中看到的那样,如果我只打开小提琴而没有打开一个演示,它就不起作用。

  • Why is that? 这是为什么?
  • And how can i solve this problem? 我该如何解决这个问题?
  • How should I link css in jsFiddles for jQuery? 我应该如何在jsFiddles中为jQuery链接css? Also Googles CDN contains only the JavaScript files. Googles CDN也只包含JavaScript文件。

I don't want to host my own css file, just for posting demos on jsfiddle... 我不想托管我自己的css文件,只是为了在jsfiddle上发布演示......

PS: The JSFiddle where I mentioned this behavior is http://jsfiddle.net/neysor/r9yfw/ PS:我提到这种行为的JSFiddle是http://jsfiddle.net/neysor/r9yfw/

Neysor, my sincere apologies - I was being an idiot. Neysor,真诚的道歉 - 我是个白痴。

I am indeed seeing the same problem and not getting the CSS, and I think I have found the problem. 我确实看到了同样的问题而没有获得CSS,我想我已经找到了问题。

It appears that jqueryui.com might be doing a referrer check against the request and returning a 403 to those outside of the domain (which makes sense). 似乎jqueryui.com可能正在对请求进行引荐来检查,并将403返回给域外的人(这是有道理的)。 This is why it's working when you view the UI elements in another window, since the CSS will then be cached. 这就是当你在另一个窗口中查看UI元素时它正在工作的原因,因为CSS将被缓存。

Make it work pl0x! 让它工作pl0x!

If you open up the "Manage Resources" tab and remove the 'jquery.ui.all' and replace with this http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/jquery-ui.css , all should work well (or at least better). 如果您打开“管理资源”选项卡并删除“jquery.ui.all”并替换为此http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/jquery-ui.css ,一切都应该运作良好(或者至少更好)。 Do this for any/all CSS resources. 对任何/所有CSS资源执行此操作。

I've forked your jsFiddle and seeing some improvements. 我已经分享了你的jsFiddle并看到了一些改进。

It may be worth checking in with the jsFiddle docs once you have a complete solution to see if we can get this documented (or better, fixed!) 一旦你有一个完整的解决方案,看看我们是否可以记录(或更好,修复!),可能值得使用jsFiddle文档进行检查。

Hope this helps! 希望这可以帮助!

jsfiddle documentation includes this in its "Add Resources" section : jsfiddle文档在其“添加资源”部分中包含此内容:

Warning: jsFiddle is recognizing the type of the resource by the extension. 警告:jsFiddle正在通过扩展来识别资源的类型。 If you want to use a dynamic resource please add a dummy GET variable ie http://example.com/download/js/dynamically.js?somevar=somevalue&dummy=.js . 如果您想使用动态资源,请添加一个虚拟GET变量,即http://example.com/download/js/dynamically.js?somevar=somevalue&dummy=.js This will trick jsFiddle to recognize it as JavaScript resource. 这将欺骗jsFiddle将其识别为JavaScript资源。

Doesn't quite predict your problem or your workaround but worth a try (with dummy=.css ). 不能完全预测您的问题或您的解决方法,但值得一试(使用dummy=.css )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM