日期:2014-05-16  浏览次数:20345 次

jsp输入框重置问题
完整代码如下:
<%@ page language="java" contentType="text/html; charset=utf-8"%>
<html>
  <head>  
  <title>JSP Scriptlets</title> 
  </head>
  <body> 
  <script language="javascript"> 
function show()
{
var div = document.getElementById("div1");
var i = document.getElementById("num").value;
if(i == 1)
{
div.innerHTML = "a <br/>b <br/>c <br/>";
}
else if(i == 2)
{
div.innerHTML = "我<br/>你<br/>他<br/>";
}
else if(i == 3)
{
div.innerHTML = "11是A1<br/>22是B2<br/>33是C3<br/>";
}
}
</script>
 
  请输入参数 param=1, 2, 3,来选择要显示的内容<br/>
  <form>
  <input type="text" name="num" value="" id="num"/><br/>
  <input type="submit" value="确定" onclick="show()"/><br/>
  <input type="reset" value="重置" />
  </form>
  <div id="div1"></div>
  </body>
</html>


------解决方案--------------------
HTML code

<html>
  <head>   
  <title>JSP Scriptlets</title>  
  </head>
  <body>  
  <script language="javascript">  
function show()
{
var div = document.getElementById("div1");
var i = document.getElementById("num").value;
if(i == 1)
{
div.innerHTML = "a <br/>b <br/>c <br/>";
}
else if(i == 2)
{
div.innerHTML = "我<br/>你<br/>他<br/>";
}
else if(i == 3)
{
div.innerHTML = "11是A1<br/>22是B2<br/>33是C3<br/>";
}
return false;
}
</script> 
  
  请输入参数 param=1, 2, 3,来选择要显示的内容<br/>
  <form onsubmit="return show();"> 
  <input type="text" name="num" value="" id="num"/><br/>
  <input type="submit" value="确定"/><br/> 
  <input type="reset" value="重置" /> 
  </form>
  <div id="div1"></div>
  </body>
</html>