我使用一个简单的方法makeInput()动态创建HTML表单,并且想知道如何使文本输入框每行显示一个,而不是以从右到左的方式显示。到目前为止,当您点击“添加课程”按钮时,它会在旧的旁边添加新的文字输入,而不是在新的一行上。这里是我的代码至今:HTML表单格式问题
<html>
<head>COURSES</head>
<title>Add Courses</title>
<script type="text/javascript">
var x = 0;
var f = document.createElement("form");
f.setAttribute('method',"post");
f.setAttribute('action',"tron.php");
f.id = "form1";
var s = document.createElement("input"); //input element, Submit button
s.setAttribute('type',"submit");
s.setAttribute('value',"Submit Courses");
f.appendChild(s);
function makeInput()
{
var i = document.createElement("input");
i.type = "text";
i.name = "cname"+ x;
i.id = "cname"+ x;
f.appendChild(i);
document.getElementById("test").appendChild(f);
x = x+1;
document.getElementById("course").innerHTML= "Number of courses: " + x;
}
</script>
<body>
<p id="course">Number of courses: </p>
<button onclick="makeInput()">Add Course</button>
<p id="test"></p>
</body>
</html>
添加一个''
也许? – gongzhitaao 2013-04-24 02:47:04