<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() {
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"; } } }
<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() {
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"; } } }
<form name="MyForm" method="post" action="mailto:[email protected]">改为
<form name="MyForm" method="post" action="test.asp">
test.asp页面里的代码就如我上面例子中,根据你的情况改改
<script language="javascript" type="text/javascript">
function ck()
{
var msg="信息确认\n\n";
var iname=document.getElementById("iname").value;
if(name=="None")
{
alert("请选择你的名字!");
document.getElementById("iname").value="";
document.getElementById("iname").focus();
return false;
}
else
{
msg+="你的名字 : "+iname+"\n";
if(confirm(msg)){
return true;
}else{
return false;
}
}
MyForm.submit()
}
</script>
记得在你的JS加上这个,这样才会提交表单啊
以下是JS表单代码.action=""里面的是本地路径.<!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>啊</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()
{
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(ageTest())
{
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="http://localhost/我的网站/JavaScript动态网页开发详解/困惑在这里尝试/1234.asp" >
<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="submit" name="Submit" value="提交" onclick="ck()"/>
<input type="reset" name="reset" value="重置" /> </td>
</tr>
</table>
</form></html>
接下来是ASP页面代码~把上面的<form></form>替换为:<%
dim htmlBody,i
htmlBody="<style>table{border-color:black;border-width:1px;border-style:Solid;font-size:9pt;width:100%;border-collapse:collapse;}"
htmlBody=htmlBody & "td{border-color:black;border-width:1px;border-style:Solid;height:20px}</style>"
htmlBody=htmlBody & "<table align='center' width='300' cellpadding='0' cellspacing='0'>"
htmlBody=htmlBody & "<tr>"
htmlBody=htmlBody & "<td colspan='4' align='center' bgcolor='gray'>学生登记信息</td>"
htmlBody=htmlBody & "</tr>"
htmlBody=htmlBody & "<tr>"
htmlBody=htmlBody & "<td colspan='2'>学校</td>"
htmlBody=htmlBody & "<td colspan='2'>" & Request.Form("itemname") & "</td>"
htmlBody=htmlBody & "</tr>"
for i=1 to Request.Form("HostID").count
htmlBody=htmlBody & "<tr>"
htmlBody=htmlBody & "<td>Server"&i&"</td>"
htmlBody=htmlBody & "<td>" & Request.Form("姓名")(i) & "</td>"
htmlBody=htmlBody & "<td>HostID"&i&"</td>"
htmlBody=htmlBody & "<td>" & Request.Form("年龄")(i) & "</td>"
htmlBody=htmlBody & "</tr>"
Next htmlBody=htmlBody & "</table>"
//发送邮件部分
set jmail=Server.CreateObject("JMail.Message")
jmail.Silent=true
jmail.Logging=true
jmail.Charset="gb2312"
jmail.From="[email protected]"
jmail.FromName="学生登记卡"
jmail.MailServerUserName="[email protected]"
jmail.MailServerPassWord="12345678"
jmail.AddRecipient "[email protected]"
jmail.Subject=Request.Form("laughing")
jmail.HTMLBody=htmlBody
if not jmail.Send("smtp.foxmail.com") then
Response.Write jmail.Log
else
Response.Write "注册信息发送成功"
end if
%></html>
以下是JS表单代码.action=""里面的是本地路径.
<!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>啊</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()
{
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(ageTest())
{
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="http://localhost/我的网站/JavaScript动态网页开发详解/困惑在这里尝试/1234.asp" >
<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="submit" name="Submit" value="提交" onclick="ck()"/>
<input type="reset" name="reset" value="重置" /> </td>
</tr>
</table>
</form></html>以下是ASP代码,把<form></form>中的代码替换为:
<%
//以下部分是JMail发送邮件部分
//表格设计部分
dim htmlBody,i
htmlBody="<style>table{border-color:black;border-width:1px;border-style:Solid;font-size:9pt;width:100%;border-collapse:collapse;}"
htmlBody=htmlBody & "td{border-color:black;border-width:1px;border-style:Solid;height:20px}</style>"
htmlBody=htmlBody & "<table align='center' width='300' cellpadding='0' cellspacing='0'>"
htmlBody=htmlBody & "<tr>"
htmlBody=htmlBody & "<td colspan='4' align='center' bgcolor='gray'>学生登记信息</td>"
htmlBody=htmlBody & "</tr>"
htmlBody=htmlBody & "<tr>"
htmlBody=htmlBody & "<td colspan='2'>学校</td>"
htmlBody=htmlBody & "<td colspan='2'>" & Request.Form("itemname") & "</td>"
htmlBody=htmlBody & "</tr>"
for i=1 to Request.Form("HostID").count
htmlBody=htmlBody & "<tr>"
htmlBody=htmlBody & "<td>Server"&i&"</td>"
htmlBody=htmlBody & "<td>" & Request.Form("姓名")(i) & "</td>"
htmlBody=htmlBody & "<td>HostID"&i&"</td>"
htmlBody=htmlBody & "<td>" & Request.Form("年龄")(i) & "</td>"
htmlBody=htmlBody & "</tr>"
Next htmlBody=htmlBody & "</table>"
//发送邮件部分
set jmail=Server.CreateObject("JMail.Message")
jmail.Silent=true
jmail.Logging=true
jmail.Charset="gb2312"
jmail.From="[email protected]"
jmail.FromName="学生登记卡"
jmail.MailServerUserName="[email protected]"
jmail.MailServerPassWord="12345678"
jmail.AddRecipient "[email protected]"
jmail.Subject=Request.Form("laughing")
jmail.HTMLBody=htmlBody
if not jmail.Send("smtp.foxmail.com") then
Response.Write jmail.Log
else
Response.Write "注册信息发送成功"
end if
%>
你谈不除警告是正常的
因为你用的是if(name=="None")
{
alert("请选择你的名字!");
document.getElementById("iname").value="";
document.getElementById("iname").focus();
return false;
} 这里name=="None"等于这个才弹出警告框
还有你的说不能提交是因为你没有用我说的
加上MyForm.submit() 这样的提交动作