日期:2014-05-16 浏览次数:20391 次
<!DOCTYPE html> <html> <head> <title>Test</title> <meta charset="UTF-8" /> </head> <body> <select id="s1"> <option>1</option> <option>2</option> </select> <select id="s2"></select> <script type="text/javascript"> var s2_1 = [1,2,3,4,5]; var s2_2 = [6,7,8,9,0]; document.getElementById("s1").onchange = function() { if (1==this.value) { document.getElementById("s2").options.length = 0; for (var i=0;i<s2_1.length;i++) { var opt = document.createElement("option"); opt.text = s2_1[i]; document.getElementById("s2").appendChild(opt); } }if (2==this.value) { document.getElementById("s2").options.length = 0; for (var i=0;i<s2_2.length;i++) { var opt = document.createElement("option"); opt.text = s2_2[i]; document.getElementById("s2").appendChild(opt); } } } </script> </body> </html>