form表单提交后保持输入的值
1.form表单提交后,继续保持原来输入的值
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta charset="UTF-8"> <title>form表单提交后保持输入的值</title> </head> <body> <form class="form-horizontal" method="post" action="#" onsubmit="return check(this)"> <div class="form-group"> <label for="inputEmail3" class="col-sm-3 control-label">标题:</label> <div class="col-sm-8"> <input type="text" class="form-control" id="title_name" placeholder="请输入需要添加的公告标题" required maxlength="10"> </div> </div> <div class="form-group"> <label for="inputEmail3" class="col-sm-3 control-label">内容:</label> <div class="col-sm-8"> <textarea type="text" rows="3" class="form-control" id="content" placeholder="请输入需要添加的公告内容" maxlength="30"></textarea> </div> </div> <div class="form-group"> <div class="col-sm-offset-3 col-sm-8"> <input type="submit" class="btn btn-primary " value="创建设备提交" id="load" onkeyup="xiaoha();"> </div> </div> </form> <script language="JavaScript"> //声明全局数组,用于存放取值 var inputArr = document.getElementsByTagName("input"); function check(o) { var nameStr = ""; for (var i = 0; i < inputArr.length-1; i++) { nameStr += inputArr[i].value + ";"; } nameStr += inputArr[inputArr.length - 1]; window.name = nameStr; } if (window.name) { //声明数组,用于存放从window.name中分离出的值 var nameArr = new Array(); nameArr = window.name.split(";"); for (var i = 0; i < nameArr.length; i++) { if (inputArr[i].type == "text") { inputArr[i].value = nameArr[i]; } } } </script> </body> </html>