加载CSS后触发的jQuery事件?

加载CSS后触发的jQuery事件?,第1张

加载CSS后触发的jQuery事件?

无需创建新的link元素并将其附加到头部,您可以使用AJAX调用来检索样式表的内容,并将其插入到内联样式块中。这样,您可以使用jQuery的“
complete”回调来触发检查。

$('#theme-selector a').click(function(){  var path = $(this).attr('href');  $.get(path, function(response){   //Check if the user theme element is in place - if not, create it.   if (!$('#userTheme').length) $('head').append('<style id="userTheme"></style>');   //populate the theme element with the new style (replace the old one if necessary)   $('#userTheme').text(response);  //Check whatever you want about the new style:  alert($('body').css('background-color'));  });});

我尚未实际测试此代码,因此可能存在一些语法错误,但逻辑应该足够合理。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5621261.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存