单击一个复选框时如何添加一个额外的输入表单?
问问题
735 次
2 回答
1
您需要确定将被选中的复选框,以及将包含新输入字段的容器(为了简单起见,我假设您在我的示例中需要一个文本框......将其更改为您想要的任何内容)。这是一个非常基本的示例,您必须根据自己的需要进行修改,但您明白了。
使用这个 HTML:
<input id="chk" type="checkbox" />
<div id="formContainer">
</div>
您可以应用此 JavaScript:
function CreateTextbox() {
var textBox = document.createElement("input");
textBox.setAttribute("type", "textbox");
textBox.setAttribute("id", textboxId);
textboxId++;
return textBox;
}
var textboxId = 0;
document.getElementById("chk").onclick = function () {
document.getElementById("formContainer").appendChild(CreateTextbox(textboxId));
}
于 2012-12-03T08:18:04.973 回答
0
也许这就是你需要的http://viralpatel.net/blogs/dynamic-add-textbox-input-button-radio-element-html-javascript/?您只需要add()
在单击复选框时调用该函数。
于 2012-12-03T08:19:23.370 回答