发布网友 发布时间:2022-04-10 16:50
共2个回答
懂视网 时间:2022-04-10 21:11
.childNodes[0].nodeValue; option.value=result[i].childNodes[1].childNodes[0].nodeValue;<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>动态更新下拉列表</title> </head> <script type="text/javascript"> var xmlHttp; function creatXMLHttpRequest() { if(window.ActiveXObject){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");} else if(window.XMLHttpRequest){xmlHttp=new XMLHttpRequest();} } function updateSelect() { var selected=document.all.slt1.value; creatXMLHttpRequest(); xmlHttp.onreadystatechange=processor; xmlHttp.open("GET","CreatXML?selected="+selected); xmlHttp.send(null); } function processor() { var result; if(xmlHttp.readyState==4&&xmlHttp.status==200) { result=xmlHttp.responseXML.getElementsByTagName("city"); while(document.all.slt2.length>0){ document.all.slt2.removeChild(document.all.slt2.childNodes[0]);} /*childNodes指所有子节点(包括文本节点和元素节点),当你代码这么写:<select name = "edu" id = "edu"> <option value = "博士">博士~~~</option> <option value = "本科" id="benke">本科~~~</option> //这里select和option之间,option和option之间有空白,这段空白就是文本节点;childNodes[0]指得是中间那段空白(文本节点),nodeName是#text;childNodes[1]为“博士”,nodeName是OPTION;childNodes[2]为空白,nodeName是#text;以此类推;可以用children(只获取元素节点)来代替childNodes*/ for(var i=0;i<result.length;++i) { var option=document.createElement(‘option‘); option.text=result[i].children[0].childNodes[0].nodeValue; option.value=result[i].children[1].childNodes[0].nodeValue; document.all.slt2.options.add(option,null); } } } </script> <body> <select id="slt1" onChange="updateSelect()"> <option value="1">hunan</option> <option value="2">guangdong</option> </select> <select id="slt2"> <option value="">choose your city</option> </select> </body> </html>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <servlet> <servlet-name>CreatXML</servlet-name> <servlet-class>CreatXML</servlet-class> </servlet> <servlet-mapping> <servlet-name>CreatXML</servlet-name> <url-pattern>/CreatXML</url-pattern> </servlet-mapping> </web-app>
java
1 import javax.servlet.*; 2 import javax.servlet.http.*; 3 import java.io.*; 4 public class CreatXML extends HttpServlet { 5 public void init() throws ServletException{} 6 public void destroy() {super.destroy();} 7 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 8 doPost(request, response); 9 } 10 public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { 11 response.setContentType("text/xml"); 12 response.setCharacterEncoding("UTF-8"); 13 String selected=request.getParameter("selected"); 14 PrintWriter out=response.getWriter(); 15 out.println("<response>"); 16 if(selected.equals("1")) { 17 out.println("<city>"); 18 out.println("<cityname>changsha</cityname>"); 19 out.println("<cityvalue>1</cityvalue>"); 20 out.println("</city>"); 21 out.println("<city>"); 22 out.println("<cityname>xiangtan</cityname>"); 23 out.println("<cityvalue>2</cityvalue>"); 24 out.println("</city>"); 25 out.println("<city>"); 26 out.println("<cityname>zhuzhou</cityname>"); 27 out.println("<cityvalue>3</cityvalue>"); 28 out.println("</city>"); 29 } 30 else { 31 out.println("<city>"); 32 out.println("<cityname>guangzhou</cityname>"); 33 out.println("<cityvalue>1</cityvalue>"); 34 out.println("</city>"); 35 out.println("<city>"); 36 out.println("<cityname>shenzhen</cityname>"); 37 out.println("<cityvalue>2</cityvalue>"); 38 out.println("</city>"); 39 out.println("<city>"); 40 out.println("<cityname>dongwan</cityname>"); 41 out.println("<cityvalue>3</cityvalue>"); 42 out.println("</city>"); 43 44 } 45 out.println("</response>"); 46 out.flush(); 47 out.close(); 48 } 49 }
其实很简单啊
【示例】教你简单用Java写一个动态更新的下拉列表(无数据库)
标签:XML character val cat element vax 字符 onchange nan
热心网友 时间:2022-04-10 18:19
以上你说的部类,我并看见。不知道LZ说的是不是这个意思:1。你想知道ssh怎么协调运作2。想知道内部类做什么用3。理解方法和类的区别以及具体使用ssh大致可以这样理解:struts:控制器,根据业务需要负责页面的跳转,传递数据spring:管理作用,对象的生命周期,销毁,创建等等hibernate:封装数据的处理,主要对数据库的操作,比如:增删改查等------------------------------如需具体了解可以继续咨询,谢谢!追问这基本的知道,你有看清楚我的问题没