javascript alert弹出对话框时如何出去确定和取消两个按钮?

JavaScript020

javascript alert弹出对话框时如何出去确定和取消两个按钮?,第1张

用的不是alert对话框,是confirm<br>confirm(str)<br>参数str:你要说的话或问题;<br>

返回值

:bool类型,返回用户是否点击确定。如果点击确定,返回true,如果点击取消或小叉子关闭对话框,返回false;<br>var r=confirm("确认还是取消?")<br>console.log(r)

你可以咋点击SubmitForm方法里面调起模态框,然后模态框里面的两个按钮定义两个方法,一个确认一个取消,然后在确认方法里面取提交你的form;

或者在模态框上定义一个方法,通过传参去判断是确认还是取消,然后在确认方法里面取提交你的form;

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />

<title>μ??</title>

<style type="text/css">

*{ padding:0margin:0list-style-type:none}

body{font-family: "??"font-size: 12px}

#t_con{ width:460pxline-height:20pxcolor:#00Fcursor:pointermargin:20px auto 0 autoborder:1px #09C dashedtext-align:center}

#t_area1{ width:268pxheight:118pxoverflow:hiddenborder:2px #09C solidbackground-color:#F1F9FCmargin:10px autopadding-bottom:10pxdisplay:none}

#t_area{ width:268pxheight:118pxoverflow:hiddenborder:2px #09C solidbackground-color:#F1F9FCmargin:10px autopadding-bottom:10pxdisplay:none}

#t_area ul{ margin:10px 0}

#t_area li{ width:60pxheight:18pxfloat:leftdisplay:inlinetext-align:centerline-height:18pxmargin:4px auto auto 5px}

#t_area li a{ color:#ffftext-decoration:none}

#t_area li a:hover,a:active{ color:#ffftext-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=0i<arealist.lengthi++){

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>