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.οnclick=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="输入" οnclick="ss()">
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在HTML中,可以使用JavaScript的`alert()`函数来创建一个对话框。`alert()`函数会在浏览器中显示一个带有消息内容的对话框,直到用户关闭它为止。 以下是一个简单的示例: ```html <button onclick="alert('这是一个对话框!')">点击我</button> ``` 当用户点击上面的按钮时,就会一个对话框,显示消息“这是一个对话框!”。 然而,这种方式并不是最佳的网页交互方式,因为它会打断用户的操作流程,而且通常不会提供用户反馈。在现代的网页设计中,更常见的是使用CSSJavaScript来创建自定义的对话框。 例如,你可以使用CSS来设置对话框的样式,然后用JavaScript来控制对话框的显示和隐藏。下面是一个简单的示例: ```html <div id="dialog" style="display: none;">这是一个对话框</div> <script> // 显示对话框 function showDialog() { document.getElementById("dialog").style.display = "block"; } </script> <button onclick="showDialog()">点击我</button> ``` 在这个示例中,当用户点击按钮时,会调用`showDialog()`函数,这个函数会改变`dialog`元素的`display`属性,使其从默认的"none"变为"block",从而显示对话框。 以上就是一些基本的HTML对话框的介绍。在实际应用中,你可能还需要考虑更多的因素,比如如何处理不同的浏览器兼容性问题,如何使用Ajax等技术来实现更复杂的交互等等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_72431373

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值