JS动态添加

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>a.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">
  </head>
  <script language="JavaScript">
  	function openWin(){
		showModalDialog("./a2.html", window, 'dialogHeight:10;dialogWidth:20;help:no');
	}

    function addOption(eduname){
	    var optionElement=document.createElement("option");
		
	    optionElement.setAttribute("value",eduname);
	    
		var textElement=document.createTextNode(eduname);
		
		optionElement.appendChild(textElement);
		
		var eduElement=document.getElementById("edu");
		
		eduElement.appendChild(optionElement);
		
	}
  </script>
  
  <body>
	   <form name="form1" action="test.html" method="post" >
  	   	  <select edu="edu" id="edu">
  	   	  	  <option value="本科">本科</option>
  	   	  </select>
		  <input type="button" name="ok" value="添加" onclick="openWin();"/>
  	   </form>
</body>
  
</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>a2.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">
  </head>
   <script language="JavaScript">
	function setData(){
		var sdata=window.dialogArguments;
		
		//input type="text"  name="eduname" id="eduname" value="" size=8></td>
		var eduname=document.getElementById("eduname").value;
		
		
		//调用a1.html页面的函数
		sdata.addOption(eduname);
		
		window.close();
		
		
	}
  </script>
  <body>
  	   <table border="1">
  	   	 
		  <tr>
  	   	  	<td><input type="text"  name="eduname" id="eduname" value="" size=8></td>
			<td><input type="button"  name="ok"  value="确定"   onclick="setData();"></td>
  	   	  </tr>
		 
  	   </table>
  </body>
 
  
  
</html>


你可能感兴趣的:(JS动态添加)