对话框创设成功,但样式没起作用
对话框创建成功,但样式没起作用
------解决思路----------------------
function show(){
var a= createDialog();a.style.cssText = "width:300px;height:200px;background-color:#abcdef;";
document.body.appendChild(a);
};
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
*{
margin:0px;
padding:0px;
list-style:none;
border:0px;
}
button{
padding:3px 5px;
border-radius:2px;
background-color:#f50;
color:#fff;
cursor:pointer;
margin:100px 0px 0px 500px;
}
</style>
<script type="text/javascript">
//通用方法
//显示
//border-radius:5px;box-shadow:10px 10px 50px #f00;position:absolute;
function show(){
createDialog().style.cssText = "width:300px;height:200px;background-color:#abcdef;";
document.body.appendChild(createDialog());
};
//隐藏
function hide(){
/*
do sth
*/
};
//创建对话框
function createDialog(){
var div = document.createElement("div");
return div;
};
//初始化浏览器事件
window.onload = function(){
show();
};
</script>
</head>
<body>
<button id="button">test</button>
</body>
</html>
------解决思路----------------------
function show(){
var a= createDialog();a.style.cssText = "width:300px;height:200px;background-color:#abcdef;";
document.body.appendChild(a);
};