0
我正在使用以下代碼來使用JavaScript製作html5表單。使用JavaScript製作HTML表單時不能使用新行
newLine = document.createElement("br");
var optionsForm = document.createElement("form");
optionsForm.setAttribute('method',"post");
optionsForm.setAttribute('action',"submit.php");
var selectColor = document.createElement("select"); //input element, drop-down
selectColor.setAttribute('type',"select");
selectColor.setAttribute('name',"colorMenu");
selectColor.setAttribute('id',"colorMenuID");
// Populate drop-down menu
var option = document.createElement("option");
option.text = "Select Color:";
option.value = "selectColor";
selectColor.appendChild(option);
optionsForm.appendChild(selectColor);
optionsForm.appendChild(newLine);
但是,當我創建新的下拉菜單時,它與舊的菜單位於同一行。附加newLine元素似乎沒有任何作用。
u能看到
標籤出現在生成的HTML代碼?嘗試使用螢火蟲來檢查它 – dreamweiver 2013-04-22 13:23:53
你試過用\ n嗎?或nl2br(PHP的換行符) – 2013-04-22 13:25:01
你不想在''optionsForm.appendChild(selectColor)''之前運行'optionsForm.appendChild(newLine);'**? – Ian 2013-04-22 13:37:13