87,969
社区成员
发帖
与我相关
我的任务
分享
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>动态加载CSS样式</title>
<script type="text/javascript">
function func()
{
var path=document.getElementByTagName("textarea")[0].value;
alert(path);
var head =document.getElementByTagName("head")[0];
var link=head.createElement("link");
link.href=path;
link.rel="stylesheet";
link.type="text/css";
head.appendChild(link);
// alert(link.href);
}
</script>
</head>
<body>
<text>输入css地址</text>
<textarea></textarea>
<br>
<button value="动态加载CSS样式" onclick="func()">动态加载CSS样式</button>
</body>
</html>
text:
{
background-color: yellow;
font-size: 20px;
}
document.getElementsByTagName("textarea")[0].value;