asp如何实现当鼠标离开输入框,自动保存数据?

由asp动态生成一个多行表格,希望当鼠标离开任一输入框时就触发事件,把这个框里的数值保存到相应的数据集中。<%dima,bseta=server.Createobject... 由asp动态生成一个多行表格,希望当鼠标离开任一输入框时就触发事件,把这个框里的数值保存到相应的数据集中。 <%dim a,b set a=server.Createobject("Scripting.Dictionary") set b=server.Createobject("Scripting.Dictionary") i=1 do while i<6 a.add i, i*i b.add i, 5*i i=i+1 loop n=1 do while n<6 %> a<%=n%>=<input name="aa<%=n%>" value="<%=a.item(n)%>"> b<%=n%>=<input name="bb<%=n%>" value="<%=b.item(n)%>"> <br> <%n=n+1 loop%> 展开
 我来答
弘为想2263
2014-09-19 · 超过68用户采纳过TA的回答
知道答主
回答量:169
采纳率:33%
帮助的人:63.9万
展开全部
需要用到ajax,给个代码你参考吧,以前做的, 下面onKeyUp改成onmouseout就能达到类似的效果 1.asp <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <!-- #include file="conn.asp" --> <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>基础知识</title> <script src="js/ajax.js" language="javascript"></ script> <script src="js/js.js" language="javascript"></ script> <style type="text/css"> .lists{list-style-type: decimal;} </style> </head> <body> <div style="border:1px solid #333; background:#f3f3f3;padding: 5px;"> <form> 添加数组<br /> 输入个数 : <input type="text" id="txt1" name="txt1" onKeyUp="inputarray(this. value)"> </form> <p><div id="arrayform">....</div></p> </div> <br /> 数组列表 <div id="modorm"></div> <table width="100%" border="1" cellpadding="3"> <% set rs=server.CreateObject("adodb. recordset") rs.open "select * from array order by id desc",conn,3,3 do while not rs.eof %> <tr> <td><%=rs("id")%></td> <td><%=rs("array")%></td> <td><a href="#" onclick="modf('<%=rs("id")%>') ">修改</a> <a href="del.asp?id=<%=rs("id")%> " onClick="return delrecord()">删除</a></td> </tr> <% rs.movenext loop rs.close set rs=nothing %> </table> </body> </html> ajax.js //1 var xmlHttp function inputarray(str) { if (str.length >0) { var url="getarrayno.asp?arrayno=" + str xmlHttp=GetXmlHttpObject( stateChanged) xmlHttp.open("GET", url , true) xmlHttp.send(null) } else { document.getElementById(" arrayform").innerHTML="" } } function stateChanged() { if (xmlHttp.readyState<4) {document.getElementById(" arrayform").innerHTML=" loading..." } if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete" ) { document.getElementById(" arrayform").innerHTML= unescape(xmlHttp.responseText) } } var set function modf(str) { if (str.length >0) { var url="modarray.asp?id=" + str set=GetXmlHttpObject( stateChanged2) set.open("GET", url , true) set.send(null) } else { document.getElementById(" modorm").innerHTML="" } } function stateChanged2() { if (set.readyState<4) {document.getElementById(" modorm").innerHTML="正在查询..." } if (set.readyState==4 || set.readyState=="complete") { document.getElementById(" modorm").innerHTML=set. responseText } } //2 var xmlcheck function checkuser(str1,str2,str3) { if (str1.length >0&&str2.length >0) { var url="chklogin.asp?username=" + str1 + "&password="+ str2 +"&logincookie="+str3 xmlcheck=GetXmlHttpObject( stateChanged3) xmlcheck.open("GET", url , true) xmlcheck.send(null) } else { document.getElementById("err") .innerHTML="" } } function stateChanged3() { if (xmlcheck.readyState<4) {document.getElementById("err" ).innerHTML="正在登陆..." } if (xmlcheck.readyState==4 || xmlcheck.readyState==" complete") { document.getElementById("err") .innerHTML=xmlcheck. responseText if(xmlcheck.responseText==" logined") {location.href="main.asp"} } } //common function GetXmlHttpObject(handler) { var objXmlHttp=null if (navigator.userAgent.indexOf(" Opera")>=0) { alert("This doesn't work in Opera") return; } if (navigator.userAgent.indexOf(" MSIE")>=0) { var strName="Msxml2.XMLHTTP" if (navigator.appVersion.indexOf( "MSIE 5.5")>=0) { strName="Microsoft.XMLHTTP" } try { objXmlHttp=new ActiveXObject(strName) objXmlHttp.onreadystatechange= handler return objXmlHttp } catch(e) { alert("Error. Scripting for ActiveX might be disabled") return } } if (navigator.userAgent.indexOf(" Mozilla")>=0) { objXmlHttp=new XMLHttpRequest() objXmlHttp.onload=handler objXmlHttp.onerror=handler return objXmlHttp } } js.js //1 var inp1=1; var inp3=1; function add(n) { var inp2=Number(document. getElementById("txt1").value); inp=inp1+inp2; document.getElementById(" arrayinput").innerHTML+="<li id='lnum"+inp+"'><input name='num' type='text' id='num"+inp+"' size='5' onKeyUp='checknum(this.value, t his.id)' ondblclick='delinput( this.id )' ></li>"; inp1++; } function add1(n) { var inp2=Number(document. getElementById("txt2").value); inp=inp3+inp2; document.getElementById(" arrayinput2").innerHTML+="<li id='lnum2"+inp+"'><input name='num' type='text' id='num2"+inp+"' size='5' onKeyUp='checknum(this.value, t his.id)' ondblclick='delinput( this.id )' ></li>"; inp3++; } function delinput(n) { li="l"+n; document.getElementById(n). name="xxx"; document.getElementById(li). style.display="none"; document.getElementById(li). innerHTML=""; } function delinput2(n) { li="d"+n; document.getElementById(n). name="xxx"; document.getElementById(li). style.display="none"; document.getElementById(li). innerHTML=""; } function check(v) { if(IsNumeric(v)!=true) { alert("请输入数字"); document.getElementById("nums" ).value=""; document.getElementById("nums" ).focus(); } } function checkform() { var All = document.form1. getElementsByTagName( "input" ); var Length = All.length; for(var I = 0; I < Length; I++) { if(All[I].value=="") {alert("请输入所有的数字"); return false; break; } } } function checkform2() { var All = document.form2. getElementsByTagName( "input" ); var Length = All.length; for(var I = 0; I < Length; I++) { if(All[I].value=="") {alert("请输入所有要修改的数字"); return false; break; } } } function checknum(v,id) { if(IsNumeric(v)!=true) { alert("请输入数字"); document.getElementById(id). value=""; document.getElementById(id). focus(); } } function IsNumeric(port) { var pattern=/^\d+$/; if(!pattern.test(port)) return false; return true; } function delrecord() { if(confirm("确定删除?")) return true; else return false; } //2 function chklogin() { var user=document.getElementById(" username"); var pwd=document.getElementById(" password"); var logincookie=document. getElementById("logincookie"); if(user.value=="") { alert("请输入用户名"); user.focus(); return false; } if(pwd.value=="") { alert("请输入密码"); pwd.focus(); return false; } if(logincookie.checked==false) { logincookie.value=0; } else { logincookie.value=3; } if(user.value!=""&pwd.value!=" ") { //alert(logincookie.value); checkuser(user.value,pwd. value,logincookie.value); return false; } } function checkpwd() { if (document.getElementById(" password1").value==""|| document.getElementById(" password2").value=="") {alert("密码不能为空"); return false;} else if(document.getElementById(" password1").value!=document. getElementById("password2"). value) {alert("两次输入密码不一致"); document.getElementById(" password1").focus(); return false;} } getarrayno.asp <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% arrayno=request("arrayno") if IsNumeric(arrayno) then response.Write("<form name='form1' method='post' action='postarray.asp' onsubmit='return checkform()'><div><ul id=arrayinput class='lists'>") for i=1 to arrayno response.Write("<li id='lnum"&i&"'><input name='num' type='text' id='num"&i&"' size='5' onblur='checknum(this.value, th is.id)' ondblclick='delinput( this.id )' ></li>") next response.Write("</ul> 双击输入框删除该节点<input type='button' value='增加输入框' onclick='add("&arrayno&")'><br /></div><br><br><input type='submit' value='提交'><input type='hidden' name='action' value='add'><input type='hidden' name='arrayno' id='arrayno' value='"&arrayno&"'></form>") else response.write("请输入数字..") end if %> <div style="border:1px solid #333; background:#f3f3f3;padding: 5px;"> <form> 添加数组<br /> 输入个数 : <input type="text" id="txt1" name="txt1" onKeyUp="inputarray(this. value)"> </form> <p><div id="arrayform">....</div></p> </div> <br /> 数组列表 <div id="modorm"></div> <table width="100%" border="1" cellpadding="3"> <% set rs=server.CreateObject("adodb. recordset") rs.open "select * from array order by id desc",conn,3,3 do while not rs.eof %> <tr> <td><%=rs("id")%></td> <td><%=rs("array")%></td> <td><a href="#" onclick="modf('<%=rs("id")%>') ">修改</a> <a href="del.asp?id=<%=rs("id")%> " onClick="return delrecord()">删除</a></td> </tr> <% rs.movenext loop rs.close set rs=nothing %> </table> </body> </html> 参考资料: http://www.blackstar.cn
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式