js弹出层如何在增加确定和取消按钮?
下面弹出层直接会消失当你点击某个城市名后如何在修改一下代码使得在弹出层选完城市后不直接消失而是需要增加两个按钮。确定和取消。只有当点击了确定或取消弹出层才消失。谢谢<ht...
下面弹出层直接会消失当你点击某个城市名后
如何在修改一下代码使得在弹出层选完城市后不直接消失
而是需要增加两个按钮。确定和取消。
只有当点击了确定或取消 弹出层才消失。
谢谢
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>µه�</title>
<style type="text/css">
*{ padding:0; margin:0; list-style-type:none;}
body{font-family: "̎ͥ";font-size: 12px;}
#t_con{ width:460px; line-height:20px; color:#00F; cursor:pointer; margin:20px auto 0 auto; border:1px #09C dashed; text-align:center;}
#t_area1{ width:268px; height:118px;overflow:hidden; border:2px #09C solid; background-color:#F1F9FC; margin:10px auto; padding-bottom:10px;display:none; }
#t_area{ width:268px; height:118px;overflow:hidden; border:2px #09C solid; background-color:#F1F9FC; margin:10px auto; padding-bottom:10px;display:none; }
#t_area ul{ margin:10px 0;}
#t_area li{ width:60px; height:18px; float:left; display:inline; text-align:center; line-height:18px; margin:4px auto auto 5px; }
#t_area li a{ color:#fff; text-decoration:none;}
#t_area li a:hover,a:active{ color:#fff; text-decoration:underline;}
</style>
<script type="text/javascript">
function showarea(){
var con = document.getElementById("t_area");
var arealist = con.getElementsByTagName("li");
var g = document.getElementById("t_con");
var val2 = "seeeeeee";
con.style.display = "block";
for (var i=0;i<arealist.length;i++){
arealist[i].onmouseover = function(){this.style.backgroundColor = "red"}
arealist[i].onmouseout = function(){this.style.backgroundColor = "#F1F9FC"}
arealist[i].onclick = function(){
g.innerHTML = this.innerHTML ;
document.getElementById("textnew").innerHTML=g.innerHTML;//赋值给下面一个form的值
document.getElementById("ttt").value = document.getElementById("t_con").innerHTML; //赋值给下面一个form的值
con.style.display = "none";
}
}
}
function offarea(){ //dissappeared when mouse move out this div
var con = document.getElementById("t_area");
con.style.display = "none";
}
var timer;
</script>
</head>
<body>
<div id="t_con" onClick="showarea();clearTimeout(timer);return false;" onmouseout="timer=setTimeout('offarea()',3500);">
选一个吧 </div>
<div id="t_area" onmouseover="showarea() ;clearTimeout(timer);return false;" onmouseout="offarea();clearTimeout(timer)">
<ul>
<li>四川</li>
<li>上海</li>
<li>北京那个</li>
<li>香港</li>
</ul> 展开
如何在修改一下代码使得在弹出层选完城市后不直接消失
而是需要增加两个按钮。确定和取消。
只有当点击了确定或取消 弹出层才消失。
谢谢
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>µه�</title>
<style type="text/css">
*{ padding:0; margin:0; list-style-type:none;}
body{font-family: "̎ͥ";font-size: 12px;}
#t_con{ width:460px; line-height:20px; color:#00F; cursor:pointer; margin:20px auto 0 auto; border:1px #09C dashed; text-align:center;}
#t_area1{ width:268px; height:118px;overflow:hidden; border:2px #09C solid; background-color:#F1F9FC; margin:10px auto; padding-bottom:10px;display:none; }
#t_area{ width:268px; height:118px;overflow:hidden; border:2px #09C solid; background-color:#F1F9FC; margin:10px auto; padding-bottom:10px;display:none; }
#t_area ul{ margin:10px 0;}
#t_area li{ width:60px; height:18px; float:left; display:inline; text-align:center; line-height:18px; margin:4px auto auto 5px; }
#t_area li a{ color:#fff; text-decoration:none;}
#t_area li a:hover,a:active{ color:#fff; text-decoration:underline;}
</style>
<script type="text/javascript">
function showarea(){
var con = document.getElementById("t_area");
var arealist = con.getElementsByTagName("li");
var g = document.getElementById("t_con");
var val2 = "seeeeeee";
con.style.display = "block";
for (var i=0;i<arealist.length;i++){
arealist[i].onmouseover = function(){this.style.backgroundColor = "red"}
arealist[i].onmouseout = function(){this.style.backgroundColor = "#F1F9FC"}
arealist[i].onclick = function(){
g.innerHTML = this.innerHTML ;
document.getElementById("textnew").innerHTML=g.innerHTML;//赋值给下面一个form的值
document.getElementById("ttt").value = document.getElementById("t_con").innerHTML; //赋值给下面一个form的值
con.style.display = "none";
}
}
}
function offarea(){ //dissappeared when mouse move out this div
var con = document.getElementById("t_area");
con.style.display = "none";
}
var timer;
</script>
</head>
<body>
<div id="t_con" onClick="showarea();clearTimeout(timer);return false;" onmouseout="timer=setTimeout('offarea()',3500);">
选一个吧 </div>
<div id="t_area" onmouseover="showarea() ;clearTimeout(timer);return false;" onmouseout="offarea();clearTimeout(timer)">
<ul>
<li>四川</li>
<li>上海</li>
<li>北京那个</li>
<li>香港</li>
</ul> 展开
2个回答
展开全部
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>μ??</title>
<style type="text/css">
*{ padding:0; margin:0; list-style-type:none;}
body{font-family: "??";font-size: 12px;}
#t_con{ width:460px; line-height:20px; color:#00F; cursor:pointer; margin:20px auto 0 auto; border:1px #09C dashed; text-align:center;}
#t_area1{ width:268px; height:118px;overflow:hidden; border:2px #09C solid; background-color:#F1F9FC; margin:10px auto; padding-bottom:10px;display:none; }
#t_area{ width:268px; height:118px;overflow:hidden; border:2px #09C solid; background-color:#F1F9FC; margin:10px auto; padding-bottom:10px;display:none; }
#t_area ul{ margin:10px 0;}
#t_area li{ width:60px; height:18px; float:left; display:inline; text-align:center; line-height:18px; margin:4px auto auto 5px; }
#t_area li a{ color:#fff; text-decoration:none;}
#t_area li a:hover,a:active{ color:#fff; text-decoration:underline;}
</style>
<script type="text/javascript">
function showarea(){
var con = document.getElementById("t_area");
var arealist = con.getElementsByTagName("li");
var g = document.getElementById("t_con");
var val2 = "seeeeeee";
con.style.display = "block";
for (var i=0;i<arealist.length;i++){
arealist[i].onmouseover = function(){this.style.backgroundColor = "red"}
arealist[i].onmouseout = function(){this.style.backgroundColor = "#F1F9FC"}
arealist[i].onclick = function(){
//g.innerHTML = this.innerHTML ;
//document.getElementById("textnew").innerHTML=g.innerHTML;//赋值给下面一个form的值
//document.getElementById("ttt").value = document.getElementById("t_con").innerHTML; //赋值给下面一个form的值
document.getElementById("selected").value=this.innerHTML ;
//con.style.display = "none";
}
}
}
function offarea(){ //dissappeared when mouse move out this div
var con = document.getElementById("t_area");
con.style.display = "none";
}
var timer;
//新增的方法
function comfirm(){
var g = document.getElementById("t_con");
g.innerHTML = document.getElementById("selected").value;
offarea();
}
</script>
</head>
<body>
<div id="t_con" onClick="showarea();clearTimeout(timer);return false;" onmouseout="timer=setTimeout('offarea()',3500);">
选一个吧 </div>
<div id="t_area" onmouseover="showarea() ;clearTimeout(timer);return false;" onmouseout="offarea();clearTimeout(timer)">
<ul>
<li>四川</li>
<li>上海</li>
<li>北京那个</li>
<li>香港</li>
</ul>
<!-- 新增的按钮-->
<button onclick="comfirm()">确定</button><button onclick="offarea()">取消</button>
</div>
<!-- 新增的隐藏域,用来保存当前选择的城市-->
<input type="hidden" id="selected"/>
</body>
更多追问追答
追答
按钮样式你可以自己在网上找个漂亮的背景图片。
展开全部
以下是我写的js代码可以实现这个要求:
//半通明遮罩
document.writeln("");
var divGg = document.getElementById("divGg");
//弹出层
document.writeln("<div id="\"divAdMsg\"" left:0px;position:absolute;height:307px;="" width:450px;display:none;background-color:#fff;\"="">关闭弹出层");
var divAdMsg = document.getElementById("divAdMsg");
//显示打开弹出层内容
function showAdMsg()
{
if(divAdMsg)
{
divAdMsg.style.display = "";
divAdMsg.style.top = document.documentElement.scrollTop + parseInt((document.documentElement.clientHeight - divAdMsg.offsetHeight) / 2) + "px";
divAdMsg.style.left = document.documentElement.scrollLeft + parseInt((document.documentElement.clientWidth - divAdMsg.offsetWidth) / 2) + "px";
divGg.style.width = document.body.offsetWidth + "px";
if(document.body.offsetHeight < document.documentElement.scrollTop + document.documentElement.clientHeight)
divGg.style.height = document.documentElement.scrollTop + document.documentElement.clientHeight + "px";
else
divGg.style.height = document.body.offsetHeight + "px";
divGg.style.display = "";
}
}
//关闭打开弹出层内容
function closeAdMsg()
{
divAdMsg.style.display = "none";
divGg.style.display = "none";
}
showAdMsg();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询