<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
/**
* APIMethod: createStyle
* 动态创建css样式
*
* Parameters:
* css - {String} css样式 即样式颜色
*/
function createStyle(css){
if(document.all){
var style = document.createElement('style');
style.type = 'text/css';
style.styleSheet.cssText=css;
document.getElementsByTagName('head').item(0).appendChild(style);
}else{
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML=css;
document.getElementsByTagName('head').item(0).appendChild(style);
}
}
window.onload = function(){
createStyle("input{ background:red; color:yellow;font-size:20px;}input:hover{background:black;}");
}
</script>
<input type="button" class="btn btn-danger" value="按钮">
</body>
</html>
动态创建样式
最新推荐文章于 2024-08-19 08:00:00 发布