html点击按钮弹出页面获取值的实例代码
代码一:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function winOpen (strURL,strName,width,height){
theWindow = window.open (strURL,strName,"width="+width+" height="+height+" scrollbars=yes left="+(1024-width)/2+" top="+(768-height)/2);
if (theWindow.opener == null) theWindow.opener = window;
if (window.focus) theWindow.focus();
}
function save(){
alert(document.getElementById("tid").value);
alert(document.getElementById("tname").value);
}
</script>
</head>
<body>
<from action="xx.action" method="post">
<!--部门ID-->
<input type="hidden" name="typeid" id="tid" value="">
请选择部门名称:<input type="text" name="v_type_name" id="tname" size="30" value=""/>
<input type="button" name="select" value="选择..." onClick="javaScript:winOpen('list.html','列表',600,400)">
<input type="button" name="select" value="提交" onClick="javaScript:save()">
</from>
</body>
</html>
代码二:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title></title>
<script type="text/javascript">
function checkIt(){
window.opener.document.getElementById("tid").value = document.getElementById("dicId").value; //把子窗口的值,赋值给父窗口
window.opener.document.getElementById("tname").value = document.getElementById("dicName").value; //把子窗口的值,赋值给父窗口
window.close();
}
function getDicName(dicId,strDicName){
document.getElementById("dicId").value = dicId;
document.getElementById("dicName").value = strDicName;
}
</script>
</head>
<body>
<from action="xx.action" method="post" id="myform" name="myform">
<input type="hidden" name="dicId" id="dicId">
<input type="hidden" name="dicName" id="dicName">
<INPUT TYPE="radio" NAME="type" onclick="getDicName('1','行政部')">行政部
<INPUT TYPE="radio" NAME="type" onclick="getDicName('2','人事部')">人事部
<INPUT TYPE="radio" NAME="type" onclick="getDicName('3','财政部')">财政部
<INPUT TYPE="radio" NAME="type" onclick="getDicName('4','研发部')">研发部
<INPUT TYPE="radio" NAME="type" onclick="getDicName('5','产品部')">产品部
<br/>
<input type='button' name='create' value=" 确 认 " onClick="javascript:checkIt()">
<input type='button' name="cancel" onClick="javaScript:window.close()" value=" 取 消 ">
</from>
</body>
</html>