<div class="codetitle"> <span><a style="CURSOR: pointer" data="90737" class="copybut" id="copybut90737" onclick="doCopy('code90737')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code90737"> <br> <br> <br> <br><title>select.html</title> <br><br><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <br><meta http-equiv="description" content="this is my page"> <br><meta http-equiv="content-type" content="text/html; charset=UTF-8"> <br><br><!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <br><br> <br><br> <br><select id="myCourse" onchange="getCourse();"> <br><option value="" selected>--请选择一门课程--</option> <br></select> <br><br><textarea id="myares" rows="10" cols="30"></textarea> <br><script type="text/javascript"> <BR><!-- <BR>var last_select_num = 3;//加入从数据库中查询 <br><br>//动态添加第一门课程 <BR>var myOption = document.createElement("option"); <BR>myOption.value = "java"; <BR>myOption.text = "java"; <BR>myCourse.add(myOption); <br><br>//动态添加第二门课程、 <BR>myOption = document.createElement("option"); <BR>myOption.value = "oracle"; <BR>myOption.text = "oracle"; <BR>myCourse.add(myOption); <br><br>//动态添加第三门课程、 <BR>myOption = document.createElement("option"); <BR>myOption.value = "javaEE"; <BR>myOption.text = "javaEE"; <BR>myCourse.add(myOption); <br><br>function getCourse(){ <BR>myares.value += "你选择了:"+myCourse.value +"\r\n"; <BR>} <BR>--> <BR></script> <br> <br> <br> </div> <br><img src="http://files.jb51.net/file_images/article/201401/201401261546431.gif?2014026154658" alt="动态添加option及createElement使用示例_javascript技巧" >