简体   繁体   English

javascript动态加载CSS和JS文件

[英]javascript load dynamically css and js files

I am using laravel 4 and I have a file style-switcher.js 我正在使用laravel 4并且有一个文件style-switcher.js

yepnope([ yepnope([

{load: 'assets/css/style-switcher.css' },
{load: 'assets/lib/colorpicker/css/colorpicker.css'},
{
    load: 'assets/css/colorpicker_hack.css'
},
{
    load: 'assets/lib/cssbeautify/cssbeautify.js'
},
{
    load: 'assets/lib/colorpicker/js/bootstrap-colorpicker.js',

How can I load this css file dynamically? 如何动态加载此CSS文件? How to include the base path? 如何包含基本路径? For header and footer js and css I use 对于页眉和页脚js和CSS,我使用

`{{ HTML::script('assets/...`) }}

But can't do the same with this js file 但是不能与此js文件做同样的事情

just change the href of the css style tag 只需更改css样式标签的href

<link id="dynamic css" href="/old_css_path">
$('#dynamic_css').attr('href','/new_css_path')

or 要么

if you want to append a new css, without removing other, $('head').append('') 如果要添加新的CSS而不删除其他CSS,则$('head')。append('')

no need to include base path of your website, just make sure you add backslash in starting of ever css path. 无需包括网站的基本路径,只需确保在Ever CSS路径的开头添加反斜杠即可。

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

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