您好,欢迎访问一九零五行业门户网

浅谈javascript中的三种弹窗

js中三种弹窗
1)alert 弹出警告 无返回值---------alert('第一行\n第二行');
2)confirm()选择确定或取消,返回t或f----var result = confirm('是否删除!');
3)prompt()弹出输入框,返回输入内容----var value = prompt('输入你的名字:', '请在这里输入名字');
当然也可以自定义好看的样式。下面代码有问题明天再改。
<script> //window.confirm //prompt window.alert = function(title,str) { var shield = document.createelement("div"); shield.id = "shield"; shield.style.position = "absolute"; shield.style.left = "0px"; shield.style.top = "0px"; shield.style.width = "100%"; shield.style.height = document.body.scrollheight+"px"; //弹出对话框时的背景颜色 shield.style.background = "#fff"; shield.style.textalign = "center"; shield.style.zindex = "25"; //背景透明 ie有效 //shield.style.filter = "alpha(opacity=0)"; var alertfram = document.createelement("div"); alertfram.id="alertfram"; alertfram.style.position = "absolute"; alertfram.style.left = "50%"; alertfram.style.top = "50%"; alertfram.style.marginleft = "-225px"; alertfram.style.margintop = "-75px"; alertfram.style.width = "450px"; alertfram.style.height = "150px"; alertfram.style.background = "#ff0000"; alertfram.style.textalign = "center"; alertfram.style.lineheight = "150px"; alertfram.style.zindex = "300"; strhtml = "<ul style=\"list-style:none;margin:0px;padding:0px;width:100%\">\n"; strhtml += " <li style=\"background:#dd828d;text-align:left;padding-left:20px;font-size:14px;font-weight:bold;height:25px;line-height:25px;border:1px solid #f9cade;\">" + title + "</li>\n"; strhtml += " <li style=\"background:#fff;text-align:center;font-size:12px;height:120px;line-height:120px;border-left:1px solid #f9cade;border-right:1px solid #f9cade;\">" + str + "</li>\n"; strhtml += " <li style=\"background:#fdeef4;text-align:center;font-weight:bold;height:25px;line-height:25px; border:1px solid #e85727;\"><input type=\"button\" value=\"确 定\" onclick=\"dook()\" /></li>\n"; strhtml += "</ul>\n"; alertfram.innerhtml = strhtml; document.body.appendchild(alertfram); document.body.appendchild(shield); var ad = setinterval("doalpha()",5); this.dook = function(){ alertfram.style.display = "none"; shield.style.display = "none"; } alertfram.focus(); document.body.onselectstart = function(){return false;}; } </script>
其它类似信息

推荐信息