把alert(sum)改成confirm(sum)就可以了啊
解决方案 »
- 弹出窗口
- jquery怎么获取父页面最后一个元素
- jquery each 内部的延时这样写可有用啊?
- Extjs 的Panel自适应高度问题,附图
- 客户端如何用javascript打开服务端日志文件?
- 为什么“~”显示在页面上总是“?”
- 求助,怎么用javascript来控制纵打、横打??
- 高分!!!请高手指点!!!用jvavascript在asp.net中写个新建infopath文件
- 如何给某个事件指定代参数的函数?
- 求大佬,看看我的iframe父页面给子页面绑定点击事件为啥不点击自执行嘞?
- 请教一个用户注册正则表达式
- JS菜鸟的问题!拜求指教!关于选项卡...需要您略懂CSS,希望前辈指教!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
var test={
"str":"0",
"childbr":new Array(),
"childtr":new Array(),
"childtd":new Array(),
"childinput1":new Array(),
"childinp1":new Array(),
"childinp2":new Array(),
"childinput2":new Array(),//定义要增加文本框的数量
"add":function(){
this.childtr[this.str]=document.createElement("tr");
this.childtd[this.str]=document.createElement("td");
this.childbr[this.str]=document.createElement("br");
this.childinp1[this.str]=document.createElement("span");
this.childinp2[this.str]=document.createElement("span");
this.childinput1[this.str]=document.createElement("input");
this.childinput2[this.str]=document.createElement("input");
document.getElementById("table1").appendChild(this.childtr[this.str]);
this.childtr[this.str].appendChild(this.childtd[this.str]);
this.childtd[this.str].appendChild(this.childinp1[this.str]);
this.childinp1[this.str].innerHTML="姓名";
this.childtd[this.str].appendChild(this.childinput1[this.str]);
this.childtd[this.str].appendChild(this.childinp2[this.str]);
this.childinp2[this.str].innerHTML="性别";
this.childtd[this.str].appendChild(this.childinput2[this.str]);
this.childtd[this.str].appendChild(this.childbr[this.str]);
this.str=parseInt(this.str+1);
},
"delet":function(){
this.str--;
document.getElementById("table1").removeChild(this.childtr[this.str]);
},
"show":function(){
var awherevalue={
"name":new Array(),
"sex":new Array(),
}
awherevalue.name[0]=this.childinput1[0].value.toString();
awherevalue.sex[0]=this.childinput2[0].value.toString();
var sum=this.childinp1[0].innerHTML+":"+this.childinput1[0].value.toString()+" "+this.childinp2[0].innerHTML+":"+this.childinput2[0].value.toString()+"\n";
for(var i=1;i<this.str;i++){
awherevalue.name[i]=this.childinput1[i].value.toString();
awherevalue.sex[i]=this.childinput2[i].value.toString();
sum=sum+this.childinp1[i].innerHTML+":"+this.childinput1[i].value.toString()+" "+this.childinp2[i].innerHTML+":"+this.childinput2[i].value.toString()+"\n";}
confirm(sum);
return awherevalue;}
}function addinput(){
test.add();
}
function deletinput(){
test.delet();
}
function showvalue(){
var awherevalue={
"name":new Array(),
"sex":new Array(),
}
awherevalue=test.show();
alert(awherevalue.name[0]+" "+awherevalue.sex[0])
window.open("target.html?awherevalue="+awherevalue)
}
</script>
</head>
<body>
<form method="post" name="RegForm" >
<table id="table1" width="570" border="0" cellspacing="10" align="left">
</table>
<table >
<tr>
<td >
<input id="btnAdd" type="button" onclick="addinput()" value="增加节点" />
<input id="btnRemove" type="button" onclick="deletinput();" value="移去节点"/> </td>
</tr>
<tr>
<td align="center">
<input type="submit" name="Submit" onclick="showvalue()" value="提交" />
<input type="reset" name="reset" value="重置" /> </td>
</tr>
</table>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
var awherevalue={
"name":new Array(),
"sex":new Array(),
}
var test={
"str":"0",
"childbr":new Array(),
"childtr":new Array(),
"childtd":new Array(),
"childinput1":new Array(),
"childinp1":new Array(),
"childinp2":new Array(),
"childinput2":new Array(),//定义要增加文本框的数量
"add":function(){
this.childtr[this.str]=document.createElement("tr");
this.childtd[this.str]=document.createElement("td");
this.childbr[this.str]=document.createElement("br");
this.childinp1[this.str]=document.createElement("span");
this.childinp2[this.str]=document.createElement("span");
this.childinput1[this.str]=document.createElement("input");
this.childinput2[this.str]=document.createElement("input");
document.getElementById("table1").appendChild(this.childtr[this.str]);
this.childtr[this.str].valign="top";
this.childtr[this.str].appendChild(this.childtd[this.str]);
this.childtd[this.str].appendChild(this.childinp1[this.str]);
this.childinp1[this.str].innerHTML="姓名";
this.childtd[this.str].appendChild(this.childinput1[this.str]);
this.childtd[this.str].appendChild(this.childinp2[this.str]);
this.childinp2[this.str].innerHTML="性别";
this.childtd[this.str].appendChild(this.childinput2[this.str]);
this.childtd[this.str].appendChild(this.childbr[this.str]);
this.str=parseInt(this.str+1);
},
"delet":function(){
this.str--;
this.childtd[this.str].removeChild(this.childinp1[this.str]);
this.childtd[this.str].removeChild(this.childinput1[this.str]);
this.childtd[this.str].removeChild(this.childinp2[this.str]);
this.childtd[this.str].removeChild(this.childinput2[this.str]);
this.childtr[this.str].removeChild(this.childtd[this.str]);
document.getElementById("table1").removeChild(this.childtr[this.str]);
},
"show":function(){
awherevalue.name[0]=this.childinput1[0].value.toString();
awherevalue.sex[0]=this.childinput2[0].value.toString();
var sum=this.childinp1[0].innerHTML+":"+this.childinput1[0].value.toString()+" "+this.childinp2[0].innerHTML+":"+this.childinput2[0].value.toString()+"\n";
for(var i=1;i<this.str;i++){
awherevalue.name[i]=this.childinput1[i].value.toString();
awherevalue.sex[i]=this.childinput2[i].value.toString();
sum=sum+this.childinp1[i].innerHTML+":"+this.childinput1[i].value.toString()+" "+this.childinp2[i].innerHTML+":"+this.childinput2[i].value.toString()+"\n";}
return sum;
}
}function addinput(){
test.add();
}
function deletinput(){
test.delet();
}
function showvalue(){
var sum;
sum=test.show();
if(confirm(sum))
window.open(target.html);
else{
return false;
}
}</script>
</head>
<body><form method="post" name="RegForm" >
<table id="table1" border="0" cellspacing="10" align="left" >
</table>
<table style="position:absolute; bottom:92px; left: 21px;">
<tr>
<td >
<input id="btnAdd" type="button" onclick="addinput()" value="增加节点" />
<input id="btnRemove" type="button" onclick="deletinput();" value="移去节点"/> </td>
</tr>
<tr>
<td align="center" >
<input type="button" name="Submit" onclick="showvalue()" value="提交" />
<input type="reset" name="reset" value="重置" /> </td>
</tr>
</table>
</form>
</body>
</html>这个应该可以了,你试试.在新页面通过opener.awherevalue.name[i]和opener.awherevalue.sex[i]来访问数据.红色部分type不要用submit,要不然页面会被重新加载,然来的数据就没了.还有一个问题,就是删除后再添加,那个文本框的位置不对,这个我再研究研究
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<title>困惑好9的问题</title>
<style type="text/css">
body
{
font-size:12px;
}
.STYLE6 {color: #000000; font-weight: bold; }
.STYLE7 {font-style:italic; font-weight: bold; }
</style>
<script type="text/javascript" language="javascript">
//增加一个TextBox
function Add()
{
var table=document.getElementById("table");
var num=document.getElementsByName("性别").length;
if(num>=2)
{
var remove=document.getElementById("btnRemove");
remove.style.visibility="visible";
}
var tr=table.insertRow(table.rows.length-2);
var td1=tr.insertCell();
var td2=tr.insertCell();
var td3=tr.insertCell();
var td4=tr.insertCell();
//var IDVal="性别"+(num+1);
//alert(IDVal);
td1.innerText="姓名"+(num+1);
td2.innerHTML="<input type='Text' name='姓名' id='姓名"+(num+1)+"' size='18'>";
td3.innerText="*性别"+(num+1);
td4.innerHTML="<input type='Text' name='性别' id='性别1"+(num+1)+"' size='32'>";
//alert(td2.innerHTML);
}
//移去最后一个TextBox
function Remove()
{
var table=document.getElementById("table");
var num=document.getElementsByName("性别").length;
if(num<=3)
{
var remove=document.getElementById("btnRemove");
remove.style.visibility="hidden";
}
table.deleteRow(table.rows.length-3);
}
function ck()
{
var msg="信息确认: \n \n";
var itemname=document.getElementById("itemname").value;
if (itemname=="")
{
alert("项目名称不能为空!");
document.getElementById("itemname").value="";
document.getElementById("itemname").focus();
return false;
}
else
{
msg+="学校 : "+itemname+"\n";
//获取所有input文本框
var inputList = document.getElementsByTagName("INPUT"); for (var i = 0; i < inputList.length; i++) {
if (inputList[i].type == "text" || inputList[i].id != "itemname") {
if (inputList[i].name == "姓名") {
msg += "姓名 : " + inputList[i].value;
} if (inputList[i].name == "性别") {
msg += "性别 : " + inputList[i].value + "\n";
}
}
}
if(confirm(msg)){
return true;
}else{
return false;
}
}
} </script>
<form method="post" name="RegForm" action="target.html" >
<table id="table" width="570" border="0" cellspacing="10" align="left">
<tr>
<p>学校 : <input type="text" name="itemname" id="itemname" value="" /> </p>
<td width="43">姓名1</td>
<td width="126"><input name="姓名" type="text" id="姓名1" size="18" /></td>
<td width="108">*性别1 </td>
<td width="235"><input name="性别" id="性别1" type="text" size="32" /></td>
</tr>
<tr>
<td>姓名2 </td>
<td><input name="姓名" type="text" id="姓名2" size="18" /></td>
<td>*性别2 </td>
<td><input name="性别" id="性别2" type="text" size="32"/></td>
</tr>
<tr>
<td colspan="2">
<input id="btnAdd" type="button" onclick="Add()" value="增加节点" />
<input id="btnRemove" type="button" style="visibility:hidden" onclick="Remove();" value="移去节点"/> </td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="button" name="Submit" value="提交" onclick="ck()"/>
<input type="reset" name="reset" value="重置" /> </td>
</tr>
</table>
</form></html>
function ck()
{
var 年龄1=document.all.RegForm.年龄1.value;
var num=document.getElementsByName("年龄").length;
//alert(num);
var 年龄=document.getElementsByName("年龄");
for(i=0;i<年龄.length;i++)
{
if(年龄[i].value.length!=2)
{
alert("年龄"+(i+1)+"位数错误!请确保年龄为2位数字");
document.getElementById("年龄"+(i+1)).focus();
return false;
}
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<title>困惑好9的问题</title>
<style type="text/css">
body
{
font-size:12px;
}
.STYLE6 {color: #000000; font-weight: bold; }
.STYLE7 {font-style:italic; font-weight: bold; }
</style>
<script type="text/javascript" language="javascript">
//增加一个TextBox
function Add()
{
var table=document.getElementById("table");
var num=document.getElementsByName("性别").length;
if(num>=2)
{
var remove=document.getElementById("btnRemove");
remove.style.visibility="visible";
}
var tr=table.insertRow(table.rows.length-2);
var td1=tr.insertCell();
var td2=tr.insertCell();
var td3=tr.insertCell();
var td4=tr.insertCell();
//var IDVal="性别"+(num+1);
//alert(IDVal);
td1.innerText="姓名"+(num+1);
td2.innerHTML="<input type='Text' name='姓名' id='姓名"+(num+1)+"' size='18'>";
td3.innerText="*性别"+(num+1);
td4.innerHTML="<input type='Text' name='性别' id='性别1"+(num+1)+"' size='32'>";
//alert(td2.innerHTML);
}
//移去最后一个TextBox
function Remove()
{
var table=document.getElementById("table");
var num=document.getElementsByName("性别").length;
if(num<=3)
{
var remove=document.getElementById("btnRemove");
remove.style.visibility="hidden";
}
table.deleteRow(table.rows.length-3);
}
function ck()
{
if(ageTest())
{
var msg="信息确认: \n \n";
var itemname=document.getElementById("itemname").value;
if (itemname=="")
{
alert("项目名称不能为空!");
document.getElementById("itemname").value="";
document.getElementById("itemname").focus();
return false;
}
else
{
msg+="学校 : "+itemname+"\n";
//获取所有input文本框
var inputList = document.getElementsByTagName("INPUT"); for (var i = 0; i < inputList.length; i++) {
if (inputList[i].type == "text" || inputList[i].id != "itemname") {
if (inputList[i].name == "姓名") {
msg += "姓名 : " + inputList[i].value;
} if (inputList[i].name == "性别") {
msg += "性别 : " + inputList[i].value + "\n";
}
}
}
if(confirm(msg)){
return true;
}else{
return false;
}
}
}
}function ageTest()
{
var ageList=document.getElementsByName("年龄");
for(i=0;i<ageList.length;i++)
{
if(ageList[i].value.length >2 || isNaN(ageList[i].value))
{
alert("年龄"+(i+1)+"位数错误!请确保年龄为2位数字");
ageList[i].focus();
return false;
}
} return true;
} </script>
<form method="post" name="RegForm" action="target.html" >
<table id="table" width="570" border="0" cellspacing="10" align="left">
<tr>
<p>学校 : <input type="text" name="itemname" id="itemname" value="" /> </p>
<td width="43">姓名1</td>
<td width="126"><input name="姓名" type="text" id="姓名1" size="18" /></td>
<td width="108">*性别1 </td>
<td width="235"><input name="性别" id="性别1" type="text" size="32" /></td>
<td width="108">*年龄1 </td>
<td width="235"><input name="年龄" id="年龄1" type="text" size="32" /></td>
</tr>
<tr>
<td>姓名2 </td>
<td><input name="姓名" type="text" id="姓名2" size="18" /></td>
<td>*性别2 </td>
<td><input name="性别" id="性别2" type="text" size="32"/></td>
<td width="108">*年龄2 </td>
<td width="235"><input name="年龄" id="年龄2" type="text" size="32" /></td>
</tr>
<tr>
<td colspan="2">
<input id="btnAdd" type="button" onclick="Add()" value="增加节点" />
<input id="btnRemove" type="button" style="visibility:hidden" onclick="Remove();" value="移去节点"/> </td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="button" name="Submit" value="提交" onclick="ck()"/>
<input type="reset" name="reset" value="重置" /> </td>
</tr>
</table>
</form></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<title>困惑好9的问题</title>
<style type="text/css">
body
{
font-size:12px;
}
.STYLE6 {color: #000000; font-weight: bold; }
.STYLE7 {font-style:italic; font-weight: bold; }
</style>
<script type="text/javascript" language="javascript">
//增加一个TextBox
function Add()
{
var table=document.getElementById("table");
var num=document.getElementsByName("年龄").length;
if(num>=2)
{
var remove=document.getElementById("btnRemove");
remove.style.visibility="visible";
}
var tr=table.insertRow(table.rows.length-2);
var td1=tr.insertCell();
var td2=tr.insertCell();
var td3=tr.insertCell();
var td4=tr.insertCell();
//var IDVal="性别"+(num+1);
//alert(IDVal);
td1.innerText="姓名"+(num+1);
td2.innerHTML="<input type='Text' name='姓名' id='姓名"+(num+1)+"' size='18'>";
td3.innerText="*性别"+(num+1);
td4.innerHTML="<input type='Text' name='年龄' id='年龄"+(num+1)+"' size='32'>";
//alert(td2.innerHTML);
}
//移去最后一个TextBox
function Remove()
{
var table=document.getElementById("table");
var num=document.getElementsByName("年龄").length;
if(num<=3)
{
var remove=document.getElementById("btnRemove");
remove.style.visibility="hidden";
}
table.deleteRow(table.rows.length-3);
}
function ck()
{
if(ageTest())
{
var msg="信息确认: \n \n";
var itemname=document.getElementById("itemname").value;
if (itemname=="")
{
alert("项目名称不能为空!");
document.getElementById("itemname").value="";
document.getElementById("itemname").focus();
return false;
}
else
{
msg+="学校 : "+itemname+"\n";
//获取所有input文本框
var inputList = document.getElementsByTagName("INPUT"); for (var i = 0; i < inputList.length; i++) {
if (inputList[i].type == "text" || inputList[i].id != "itemname") {
if (inputList[i].name == "姓名") {
msg += "姓名 : " + inputList[i].value;
} if (inputList[i].name == "年龄") {
msg += "年龄 : " + inputList[i].value + "\n";
}
}
}
if(confirm(msg)){
return true;
}else{
return false;
}
}
}
}function ageTest()
{
var ageList=document.getElementsByName("年龄");
for(i=0;i<ageList.length;i++)
{
if(ageList[i].value.length >2 || isNaN(ageList[i].value) || ageList[i].value=="")
{
alert("年龄"+(i+1)+"不可为空,且为2位数字");
ageList[i].focus();
return false;
}
} return true;
} </script>
<form method="post" name="RegForm" action="target.html" >
<table id="table" width="570" border="0" cellspacing="10" align="left">
<tr>
<p>学校 : <input type="text" name="itemname" id="itemname" value="" /> </p>
<td width="43">姓名1</td>
<td width="126"><input name="姓名" type="text" id="姓名1" size="18" /></td>
<td width="108">*年龄1 </td>
<td width="235"><input name="年龄" id="年龄1" type="text" size="32" /></td>
</tr>
<tr>
<td>姓名2 </td>
<td><input name="姓名" type="text" id="姓名2" size="18" /></td>
<td width="108">*年龄2 </td>
<td width="235"><input name="年龄" id="年龄2" type="text" size="32" /></td>
</tr>
<tr>
<td colspan="2">
<input id="btnAdd" type="button" onclick="Add()" value="增加节点" />
<input id="btnRemove" type="button" style="visibility:hidden" onclick="Remove();" value="移去节点"/> </td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="button" name="Submit" value="提交" onclick="ck()"/>
<input type="reset" name="reset" value="重置" /> </td>
</tr>
</table>
</form></html>