使用YUI3动态加载样式表
我使用 YUI3 'Get' 动态加载样式表。然而,据我所知,它没有给我任何方法来为这些新样式表设置 id,这会导致样式表在用户浏览网站时多次加载。
var css_obj = Y.Get.css(location.pathname+"/../css/"+jta["iss"]+".css");
有没有人有任何其他方法可以做到这一点,以便我可以在加载 css 之前进行测试(如果它已经加载)?
谢谢
I am dynamically loading stylesheets using YUI3 'Get'. which is working flawlessly however, as far as I can tell it doesn't give me any way to set id's for these new stylesheets which is causing the stylesheet to be loaded multiple times as the user navigates around the site.
var css_obj = Y.Get.css(location.pathname+"/../css/"+jta["iss"]+".css");
Does anyone have any other way of doing this so that I can test prior to loading the css, if it has already been loaded?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试使用自己的变量来检查它是否已被加载?
如果你使用 jQuery 你可以写
Did you try using your own variable to check if it's already been loaded?
and if you're using jQuery you could write
我喜欢亨特的解决方案。不过,您确实可以访问插入的
link
节点,并且您可以根据需要设置其 id:http://ericmiraglia.com/yui/demos/cssid.php
I like Hunter's solution. You do have access to the inserted
link
node, though, and you can set its id if you wish:http://ericmiraglia.com/yui/demos/cssid.php