
无需创建新的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')); });});我尚未实际测试此代码,因此可能存在一些语法错误,但逻辑应该足够合理。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)