相关疑难解决方法(0)

无法从Chrome 64中的本地css文件访问cssRules

这是一个简单的问题示例:

<html>
<head>
<link rel='stylesheet' href='myStyle.css'>
<script>
window.onload=function(){
    try{
        alert(document.styleSheets[0]); // works
        alert(document.styleSheets[0].cssRules); // doesn't even print undefined
    }catch(e){alert(e)} // catch and alert the error
}
</script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

myStyle.css body{background-color:green;}

如果你使用脚本工作正常 <style></style>

解决方案:
1,作品文件时在线/本地主机
2.作品与其他浏览器(如IE浏览器,微软边缘,火狐)
3 铬--allow-文件访问从-文件

html javascript css google-chrome cors

17
推荐指数
1
解决办法
2万
查看次数

获取所有css类背景和颜色属性值

我想获得所有CSS声明的所有背景和颜色属性值.

例如:

    body {
      background: #fff;
    }
    .aaa {
      background: #dedede;
      color: #000
    }
    .text {
      color: #333;
      padding: 10px
    }
Run Code Online (Sandbox Code Playgroud)

我想获得这样的输出,并且这些属性的值需要存储在数组中.

    body {
      background: #fff;
    }
    .aaa {
      background: #dedede;
      color: #000
    }
    .text {
      color: #333;
    }
Run Code Online (Sandbox Code Playgroud)

我尝试使用jQuery来做到这一点.我可以得到一个特定类的背景属性值,如.aaa.text.我如何获得所有类的值?

$('#btn-invert').on('click', function() {
  var color = $("body").css("background");
  // var test = invertColor("#00a3fe"); 
  console.log(color); 
});
Run Code Online (Sandbox Code Playgroud)

javascript css arrays jquery

2
推荐指数
1
解决办法
211
查看次数

标签 统计

css ×2

javascript ×2

arrays ×1

cors ×1

google-chrome ×1

html ×1

jquery ×1