gpt4 book ai didi

javascript - jQuery 附加一个 CSS 并运行一个函数?

转载 作者:可可西里 更新时间:2023-11-01 12:53:27 24 4
gpt4 key购买 nike

我正在尝试将 CSS 文件附加到当前 HTML 页面,如下所示:

    var css = jQuery("<link>");
css.attr({
rel: "stylesheet",
type: "text/css",
href: "http://domain.com/chron/css/jquery.gritter.css"
});
$("head").append(css);

下载 css 文件后,我想调用一个特定的函数。我想我会把函数调用放在 $('head').append(css); 行之后,但我不确定这是否能保证在调用之前先下载 css 文件功能。有人可以告诉我该怎么做吗?

最佳答案

如何通过 AJAX 检索并将其放置在 STYLE 元素中:

$.ajax( {
url: 'http://domain.com/chron/css/jquery.gritter.css'
dataType: 'text'
success: function( data )
{
$( '<style>' )
.attr( 'type', 'text/css' )
.text( data )
.appendTo( 'head' );

yourFunction();
}
} );

关于javascript - jQuery 附加一个 CSS 并运行一个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5055058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com