<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>count.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <style type="text/css"> .test0 {display:block;color:blue;background-color:red;border000 1px solid;z-index:1000;position:absolute;width:1024px;left:20px;top:70px;height:20} </style> </head> <script language="javascript"> var indd; function test(){ var sel=document.getElementById("sel").value; var but0 = document.getElementById("but"); var xh; var count=""; var div = document.getElementById("tx"); var m=""; xh = new ActiveXObject("Microsoft.XMLHTTP") ; if(but0.value=="stop"){ xh.onreadystatechange = function () { if (xh.readyState == 4) { indd = xh.responseText; div.innerText = indd; setTimeout("test();",1000); } } }else{ xh.onreadystatechange = function (){ } } m="http://127.0.0.1080/test/servlet/test?in="+indd+"&sel="+sel ; xh.open("POST",m,true) ; xh.send(); } function st_spf(){ var but0 = document.getElementById("but"); var but = document.getElementById("tx"); if(but0.value=="start"){ but0.value= "stop"; test() }else{ but0.value = "start"; } } </script> <body > <br><center>计数器小程序,用AJAX技术实现,后台使用SEVLET技术支持</center><br>tesdjs<br>tesdjs<br>tesdjs <div id="tx" class="test0" > start </div> <br><br> <center><input type='button' id='but' value='start' οnclick="st_spf();" /> <select id="sel" ><option value="jia" selected="selected">加</option> <option value="jian">减</option></select></center> </body> </html> //Servlet后台 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletOutputStream out = response.getOutputStream(); int i=0; String in=request.getParameter("in"); String sel=request.getParameter("sel"); if("undefined".equals(in)||in==null){ in= Integer.toString(i); } else{ i= Integer.parseInt(in); if(sel.equals("jia")){ in = Integer.toString(++i); }else{ in = Integer.toString(--i); } } out.print(in); } //dopost调用doget public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); }
和ajax相关
最新推荐文章于 2024-08-20 19:48:29 发布