简体   繁体   English

我可以从原始文件加载CSS吗?

[英]Can i load css from the original file?

Seems like to me there should be an option for that but i can't seem to find it. 在我看来,应该对此有一个选择,但我似乎找不到。

This question was asked many times but only workarounds were answered and that's not what i'm looking for. 这个问题被问过很多次,但只有解决方法得到了回答,这不是我想要的。

I am changing my css incode and i want to load the original css back instead of coding it myself, how can that be achived? 我正在更改CSS内码,但我想重新加载原始的CSS而不是自己进行编码,如何实现?

I don't wanna reload the entire file, just load some div or class css. 我不想重新加载整个文件,只加载一些div或class CSS。

See this post for a solution. 请参阅此帖子以获取解决方案。

Based on that you can do something like this: 基于此,您可以执行以下操作:

$("#fix").click(function(e) {
    e.preventDefault();
    $("div").removeAttr("style");
});​

Note: This assumes you are using JQuery to change the styles in the first place 注意:假设您首先使用JQuery更改样式

Here is a working example 这是一个有效的例子

if you're using jQuery apply 如果您使用的是jQuery,请套用

$(selector).removeAttr('style')

to your elements 对你的元素

I want to load the original css back instead of coding it myself 我想重新加载原始CSS而不是自己编码

This is not necessary. 这不是必需的。 You are trying to reload a resource that should just continue to exist. 您正在尝试重新加载应该继续存在的资源。 Once it's loaded, you don't need to load it again. 加载后,您无需再次加载。 If you need to override a style, apply a class to it. 如果您需要覆盖样式,请对其应用一个类。 To revert to original, remove the class. 要还原为原始语言,请删除课程。 That's how cascading style sheets work. 这就是级联样式表的工作方式。

If there is a particular reason the css needs to be dynamic, you can try loading css into the Document via the DOM ( document.createElement("style") etc.), but support for this is a bit sketchy I believe. 如果有特殊的原因需要使css动态化,则可以尝试通过DOM将css加载到Document中( document.createElement("style")等),但是我认为对此有点支持。

如果您想重置整个样式,而不仅仅是div,则最好使用all selector

$('*').removeAttr('style');

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

相关问题 我只能在Windows上加载CSS文件吗? - Can i load a css file only on windows? 如何将一些HTML代码加载到 <div> 但是要保留原始页面的CSS和JS? - How can I load some html code into a <div> but mantaining the css and js of the original page? 从Internet加载特定网页时如何加载本地CSS文件? - can i load local CSS file when loading a specific webpage from the internet? 如何使用JavaScript在特定情况下加载特定的css文件? - How can I load a specific css file in a specific case with JavaScript? 我可以使用node express加载css文件,但是它不起作用,某些css文件可以工作 - I can load css file with node express, but it doesn't work, some css file can work 我可以从php文件加载javascript吗? - Can I load javascript from a php file? 如何从缩小的CSS文件创建源映射回原始.less文件? - How do I create a sourcemap back to the original .less files from a minified CSS file? 我正在尝试从JavaScript内加载js和CSS文件 - I'm trying to load a js and a css file from within a javascript 如何从.load()的页面访问CSS属性? - How can i access a css attribute from a .load()'ed page? 如何加载默认值或清除另一个CSS中先前文件(引导程序)中的CSS属性? - How can you load defaultor clear a css property from a preceding file (Bootstrap) in another css?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM