当用JavaScript制作HTML表单时,新行不工作
New Line Not Working When Making HTML Form with JavaScript
我使用以下代码使用JavaScript制作html5表单。
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元素似乎没有任何效果。
我知道怎么做了。
var menuElement = document.createElement("div");
label = document.createTextNode("Label: ");
menuElement .appendChild(label);
var selectMenu = document.createElement("select");
selectMenu.setAttribute('type',"select");
selectMenu.setAttribute('name',"menuName");
selectMenu.setAttribute('id',"menuID");
menuElement.appendChild(selectMenu);
然后我添加一些选项,然后
menuElement.appendChild(newLine);
optionsForm.appendChild(menuElement);
相关文章:
- javascript中的新行不起作用
- 邮件链接在一个邮件的主题行不工作使用javascript
- 为什么javascript函数在新页面不工作
- 为什么反斜杠写在多行不工作在javascript
- Bootstrap 3等高行不工作100%在我们的网站
- 表格形式的新行不会递减
- 取消绑定事件的单击表行不工作的Jquery
- 当用JavaScript制作HTML表单时,新行不工作
- onClick在表行不工作在JavaScript/jQuery
- JS查询切换表行不工作
- 截断javascript多行不工作
- 删除表行不工作
- 换行不工作在javascript谷歌地图标签
- Javascript代码打开一个新窗口不工作在IE
- Jstree:创建新节点不工作
- 从jquery数据表中获取选定行不工作
- Javascript,通过服务器提交字符串到JSON文件,换行不工作
- yii2:处理gridview的选定行不工作- ajax post是空的
- f文件的新行不工作
- jQuery数据表-添加行不工作