javascript操作css实现弹出对话框

尝试运行代码效果:

 ------------------------------------------效果-----------------------------------------------

 

 -----------------------------------------代码-----------------------------------------------------------------------------------

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function ss(){
var div=document.createElement("div");
var textarea=document.createElement("textarea");

var button=document.createElement("input");
button.type='button';
button.value='OK';
button.onclick=function(){
document.getElementById("show").value=textarea.value;
document.body.removeChild(button);
document.body.removeChild(textarea);
document.body.removeChild(div);
}
setStyle(div,{
'position':'absolute',
'left':0,
'top':0,
'bottom':0,
'right':0,
'backgroundColor':'black',
'opacity':.5,
'filter':'alpha(opacity=50)'
});
setStyle(button,{
'position':'absolute',
'left':'250px',
'top':'160px'
})
setStyle(textarea,{
'position':'absolute',
'left':'100px',
'top':'100px'
})
document.body.appendChild(div);
document.body.appendChild(button);
document.body.appendChild(textarea);


}
function setStyle(dom,style){
for(var i in style){
if(style.hasOwnProperty(i)){
dom.style[i]=style[i];
}
}
}
</script>
</head>

<body>
<input type="text" id="show" />
<input type="button" value="输入" onclick="ss()">
</body>
</html>

 

posted @ 2015-10-11 23:14  web前端小计  阅读(2004)  评论(0编辑  收藏  举报