javascript popup提示

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript popup提示相关的知识,希望对你有一定的参考价值。

程序如下,第一栏做了个数字限制,用Alert做的弹出窗口,现在想用POPUP做提示弹出窗口,并且该窗口可以用鼠标随意拖动并可以关闭。
能帮我解决的我送分呀!
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head><title></title>
<script type = "text/javascript" >
function requiredfield()

var zip = document.getElementById("zip");
var country = document.getElementById("country");
var w = window.open("")
if(zip.value == "")
alert("ZIP/Postal code must be filled out");
zip.focus();
return false;

if(country.value == "")
alert("Country or region must be filled out");
country.focus();
return false;

else

w.document.write("ZIP/Postal code :",zip.value,"<br />");
w.document.write("Country or region :",country.value,"<br />");




</script>
<script type = "text/javascript" >
function numbercheck()
if(event.keyCode<48||event.keyCode>57)

alert("ZIP/Postal code must be a number");



</script>

</head>
<body>
<p>PERSONAL INFORMATION</p>
<form id= "myform" action ="" method="post" target="_blank">
<p>
ZIP/Postal code<br />
*<input type="text" id="zip" onkeyup="numbercheck()"/><br />
Country or region<br />
*<input type="text" id="country" /><br />
<input type="button" value="sumbit" name="submit" onclick="return requiredfield()"/>
<input type="reset" value="reset"/>
</p>
</form>
</body>
</html>

一下是弹出div层特效代码
<script type="text/javascript">
var prox;
var proy;
var proxc;
var proyc;
var isIe=(document.all)?true:false;
function setSelectState(state)

var objl=document.getElementsByTagName('select');
for(var i=0;i<objl.length;i++)

objl[i].style.visibility=state;


function mousePosition(ev)

if(ev.pageX || ev.pageY)

return x:ev.pageX, y:ev.pageY;

return
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop - document.body.clientTop
;

//关闭
function closeWindow()

if(document.getElementById('back')!=null)

document.getElementById('back').parentNode.removeChild(document.getElementById('back'));

if(document.getElementById('mesWindow')!=null)

document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));

if(isIe)
setSelectState('');

function show(id,ev)/*--打开--*/
closeWindow();
var bWidth=parseInt(document.documentElement.scrollWidth);
var bHeight=parseInt(document.documentElement.scrollHeight)<592?592:parseInt(document.documentElement.scrollHeight);
if(isIe)
setSelectState('hidden');
var back=document.createElement("div");
back.id="back";
var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
styleStr+=(isIe)?"filter:alpha(opacity=40);":"opacity:0.40;";
back.style.cssText=styleStr;
document.body.appendChild(back);

clearInterval(prox);
clearInterval(proy);
clearInterval(proxc);
clearInterval(proyc);
var o = document.getElementById(id);
o.style.display = "block";
o.style.width = "1px";
o.style.height = "1px";
prox = setInterval(function()openx(o,500),10);


function openx(o,x)/*--打开x--*/
var cx = parseInt(o.style.width);
if(cx < x)

o.style.width = (cx + Math.ceil((x-cx)/5)) +"px";

else

clearInterval(prox);
proy = setInterval(function()openy(o,300),10);


function openy(o,y)/*--打开y--*/
///
var cy = parseInt(o.style.height);
if(cy < y)

o.style.height = (cy + Math.ceil((y-cy)/5)) +"px";

else

clearInterval(proy);


function closeed(id)/*--关闭--*/
closeWindow();
clearInterval(prox);
clearInterval(proy);
clearInterval(proxc);
clearInterval(proyc);
var o = document.getElementById(id);
if(o.style.display == "block")

proyc = setInterval(function()closey(o),10);


function closey(o)/*--打开y--*/
var cy = parseInt(o.style.height);
if(cy > 0)

o.style.height = (cy - Math.ceil(cy/5)) +"px";

else

clearInterval(proyc);
proxc = setInterval(function()closex(o),10);


function closex(o)/*--打开x--*/
var cx = parseInt(o.style.width);
if(cx > 0)

o.style.width = (cx - Math.ceil(cx/5)) +"px";

else

clearInterval(proxc);
o.style.display = "none";



/*-------------------------鼠标拖动---------------------*/
var od = document.getElementById("fd");
var dx,dy,mx,my,mouseD;
var odrag;
var isIE = document.all ? true : false;
document.onmousedown = function(e)
var e = e ? e : event;
if(e.button == (document.all ? 1 : 0))

mouseD = true;


document.onmouseup = function()
mouseD = false;
odrag = "";
if(isIE)

od.releaseCapture();
od.filters.alpha.opacity = 100;

else

window.releaseEvents(od.MOUSEMOVE);
od.style.opacity = 1;



//function readyMove(e)
od.onmousedown = function(e)
odrag = this;
var e = e ? e : event;
if(e.button == (document.all ? 1 : 0))

mx = e.clientX;
my = e.clientY;
od.style.left = od.offsetLeft + "px";
od.style.top = od.offsetTop + "px";
if(isIE)

od.setCapture();
od.filters.alpha.opacity = 50;

else

window.captureEvents(Event.MOUSEMOVE);
od.style.opacity = 0.5;


//alert(mx);
//alert(my);



document.onmousemove = function(e)
var e = e ? e : event;

//alert(mrx);
//alert(e.button);
if(mouseD==true && odrag)

var mrx = e.clientX - mx;
var mry = e.clientY - my;
od.style.left = parseInt(od.style.left) +mrx + "px";
od.style.top = parseInt(od.style.top) + mry + "px";
mx = e.clientX;
my = e.clientY;



function showBackground(obj,endInt)

obj.filters.alpha.opacity+=1;
if(obj.filters.alpha.opacity<endInt)

setTimeout(function()showBackground(obj,endInt),8);


</script>
这是相应的样式
<style type="text/css">
<!--
html,body
height:100%;

*
padding:0;
margin:0;

#upcontent
list-style-position: outside;
list-style-image: none;
list-style-type: none;

#upcontent li
font-size:12px;
color:#333;
line-height:150%;

#bodyL
float:left;
width:84px;
margin-right:2px;

#tittleup
font-size:14px;
font-weight:bold;
padding-left:25px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #d0daec;
margin-bottom: 10px;
padding-bottom: 10px;

a.od
float:right;
font-size:14px;
text-decoration: none;

a.od:hover
color:#FF0000;

#fd
background:#EDF1F8;
border: 2px solid #849BCA;
margin-top:2px;
margin-left:2px;
float:left;
overflow:hidden;
position:absolute;
left:0px;
top:0px;
cursor:move;
float:left;/*filter:alpha(opacity=50);*/
z-index: 10;

.contentup
padding:20px;


-->
</style>
一下是引用的方法:
<div id="bodyL"> <a href="#" onclick = "show('fd',event);return false;"> 弹出提示</a> </div>
<div id="fd" style="display:none;filter:alpha(opacity=100);opacity:1;">
<div class="contentup"> <a href="#" class="od" onclick = "closeed('fd');return false;"> 关闭 </a>
<div id="tittleup">友情提示:</div>
<ul id="upcontent">
<li>对不起,您输入的数字超过有效范围。请输入100-200之间的数字,谢谢。</li>
</ul>
</div>
</div>

好了多的我就不说了,希望能对你有所启发。祝您成功!!!
QQ:865287652 非编程爱好者勿加!!!!!
参考技术A popup的不好,会被作为弹出窗口拦截的,其实用层来做就可以了
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head><title></title>
<script type = "text/javascript" >
function requiredfield()

var zip = document.getElementById("zip");
var country = document.getElementById("country");
var w = window.open("")
if(zip.value == "")
aletr("ZIP/Postal code must be filled out");
zip.focus();
return false;

if(country.value == "")
aletr("Country or region must be filled out");
country.focus();
return false;

else

w.document.write("ZIP/Postal code :",zip.value,"<br />");
w.document.write("Country or region :",country.value,"<br />");




</script>
<script type = "text/javascript" >
function numbercheck()
if(event.keyCode<48||event.keyCode>57)

aletr("ZIP/Postal code must be a number");



</script>

</head>
<body>
<p>PERSONAL INFORMATION</p>
<form id= "myform" action ="" method="post" target="_blank">
<p>
ZIP/Postal code<br />
*<input type="text" id="zip" onkeyup="numbercheck()"/><br />
Country or region<br />
*<input type="text" id="country" /><br />
<input type="button" value="sumbit" name="submit" onclick="return requiredfield()"/>
<input type="reset" value="reset"/>
</p>
</form>

<div style='position:absolute;z-index:200;visibility:hidden;width:300;height:200;background-color:green' id=a><font style='position:absolute;cursor:hand;left:250;top:10' onclick='sb.style.visibility=a.style.visibility="hidden"' color=snow>close</font><font color=pink id=po style='position:absolute;left:10;top:30' size=-1>这只是一个测试<br>ZIP/Postal code must be filled out</font></div>
<div id=sb style='position:absolute;z-index:100;left:-10;top:-10;filter:alpha(opacity=10);background-color:black'></div>
<script>
function aletr(bs)with(a.style)top=d.scrollTop+d.clientHeight/2-100;left=d.scrollLeft+d.clientWidth/2-150;sb.style.visibility=visibility=""with(sb.style)posWidth=d.scrollWidth+20;posHeight=d.scrollHeight+20;po.innerHTML=bsreturn false
d=document.body
a.onmousedown=function()x=event.offsetX;y=event.offsetY
a.onmousemove=function()if(event.button==1)with(a.style)posLeft=event.x-x+d.scrollLeft;posTop=event.y-y+d.scrollTopreturn false
</script>

</body>
</html>本回答被提问者采纳
参考技术B 你这样写肯定麻烦啦~

你可以先做个DIV隐藏起来,在onsubmit里面判断是否合法,
不合法再显示那个DIV啊~

(当然,DIV里面的内容,你可以随便操作,这样的思路简单多了吧)
参考技术C 百度不是有个POPUP.js可以用用

JavaScript JavaScript Popup Unobstrusive

function popup(url) {
  newWindow = window.open(url, 'name', 'height=400,width=335,scrollbars=yes');
  if (window.focus) { newWindow.focus() }
  return false;
}



// &lt;a href=&quot;link.html&quot; onclick=&quot;popup('link.html');&quot;&gt;Link&lt;/a&gt;

以上是关于javascript popup提示的主要内容,如果未能解决你的问题,请参考以下文章

popup.vue消息提示组件

JavaScript JavaScript Popup Unobstrusive

JavaScript Javascript Popup with Blocking detection

chrome扩展中popup.html和popup.js之间的函数JavaScript(考虑到来自后台的消息)[重复]

javascript Eargo Popups

javascript mailchimp-popup.js