代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <base href="<%=basePath%>"> <html> <head> <title>前台动态下拉列表添加</title> <script type="text/javascript"> function addHouse(){ var obj = document.getElementById("house"); var option = document.createElement("option");//创建option节点 option.innerText = obj.value; var parantCity = document.getElementById("houseName");//找到select子节点 parantCity.appendChild(option); } </script> </head> <body> <input type="button" value="增加房屋" οnclick="addHouse()" /> <label>请输入增加的房屋:</label> <input type="text" id="house" /> <select id="houseName"> </select> </body> </html>