<link href="../base.css" type="text/css" rel="stylesheet" id="link1" />
<title>无标题文档</title>
</head>
<body>
<div style="width:100px height:100px border:1px solid #ccc"></div>
</body>
<script>
var oLink = document.getElementById('link1')
oLink.href = '../../aaa.css' //这样就把link的链接修改为'../../aaa.css'了。
</script>
</html>
修改 webpack 打包css的引用路径方法:{
test: /\.css/,
loader: ExtractTextPlugin.extract('style-loader','css-loader!postcss-loader',{
publicPath:'../'
})
}
使用相对路径
//表示两种方法完全没问题<link rel="stylesheet" type="text/css" id="type" href="style1.css" />
<script type="text/javascript">
var oType = document.getElementById('type')
oType.href="style2.css"
$('#type').attr('href','style2.css')
</script>