Tip: you can modify some code before running
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>Javascript select combiner _</title> <script language="javascript" type="text/javascript">Function vtOption () {var s1 = document. getElementById ("select1"); var sV = s1.options [s1.selectedIndex]. value; var sT = s1.options [s1.selectedIndex]. text; alert (sV + "n" + sT);} function addOption1 () {var s1 = document. getElementById ("select1"); var newOp1 = new Option; newOp1.value = "3"; newOp1.text = "this is 3"; var newOp2 = new Option; newOp2.value = "4 "; newOp2.text = "this is 4"; s1.add (newOp1); s1.add (newOp2);} function addOption2 () {var s1 = document. getElementById ("select1"); for (var I = 3; I <5; I ++) {var newOp1 = new Option ("this is" + I, I ); // var newOp1 = new Option; // newOp1.value = I; // newOp1.text = "this is" + I; s1.add (newOp1) ;}} function addOption3 () {var s1 = document. getElementById ("select1"); s1.options. length = 0; // clear the previous options for (var I = 3; I <7; I ++) {var newOp1 = new Option ("this is" + I, i); // var newOp1 = new Option; // newOp1.value = I; // newOp1.text = "this is" + I; s1.add (newOp1) ;}} function remOption () {var s1 = document. getElementById ("select1"); for (var I = s1.options. length; I> = 0; I --) {s1.options. remove (I) ;}} function remOptionSelected () {var s1 = document. getElementById ("select1"); var I = s1.selectedIndex; // alert (I); s1.options. remove (I );}</script> </head> <body> <select name="select" id="select1"> <option value="1">This is 1</option> <option value="2">This is 2</option> </select>Value increase 1 Increase 2 increase 3 delete option delete select option</body> </html>
Tip: you can modify some code before running