我在考虑而不是并行加载所有东西.我将允许加载和显示基本的无样式布局,然后在页面加载完成后加载css文件,但是在Javascript中成为新手.我无法做到这一点.
直到现在我尝试过:
<head>
<script type='text/javascript'>
function addstyle()
{
document.getElementBytype('text/css').href='style.css';
}
</script>
<link rel="stylesheet" type="text/css" href="">
</head>
<body onload="addstyle()">
<h1>Good Morning</h1>
<p>Hello whats up</p>
<p>Hope you will have a great day ahead</p>
</body>
Run Code Online (Sandbox Code Playgroud)
在这里你可以看到,我试图style.css在浏览器中显示页面后加载,但它无法正常工作.
小智 6
试试这个:
<head>
<script type='text/javascript'>
function addstyle()
{
document.getElementById('style').href='style.css';
}
</script>
<link rel="stylesheet" id="style" type="text/css" href="">
</head>
<body onload="addstyle()">
<h1>Good Morning</h1>
<p>Hello whats up</p>
<p>Hope you will have a great day ahead</p>
</body>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3684 次 |
| 最近记录: |