document.write与document.getElementById()。innerHTML

时间:2013-11-01 00:31:20

标签: javascript

我有一个创建两组表单的脚本 - 每组有12个表单,每个表单都有一个下拉输入菜单

我有两个问题: 1.当我使用document.getElementById()。innerHTML而不是document.write时,我没有得到相同的外观。 2.使用document.write - 如何让第二组表格向左浮动?

TIA

以下是代码:

 var names = ["Sun", "Moon", "Mercury", "Venus", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto", "MC", "Asc"]

 var signs = ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"]

 document.write("<body>") 

 for (j=0;j<(12);j++){
 document.write("<form id=" + "\"" + j + "\">")
 document.write("<select id=" + "\'" + j + "\'" + "onchange='OnChange();'>")
 for (i=0;i<(12);i++){
 document.write("<option value=" + i + " name=" + signs[i] + ">" + signs[i] + "</option>")
 }

 document.write("</select><input type=" + "\"text\"><input type=" + "\"text\">" + names[j] + "<br>")

 document.write("</form>")
 }
 document.write("<br>")
 document.write("<body>") 

 for (j=12;j<(24);j++){
 document.write("<form id=" + "\"" + j + "\">")
 document.write("<select id=" + "\'" + (j-12) + "\'" + "onchange='OnChange();'>")

 for (i=0;i<(12);i++){
 document.write("<option value=" + i + " name=" + signs[i] + ">" + signs[i] + "</option>")
 }

 document.write("</select><input type=" + "\"text\"><input type=" + "\"text\">" + names[j-12] + "<br>")

 document.write("</form>")
 }
 document.write("<br>")

0 个答案:

没有答案