如何通过单击按钮创建输入字段 [英] How to create input field with a button click
本文介绍了如何通过单击按钮创建输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请谁可以帮助我想要在点击按钮时创建输入字段但是我不知道怎么做。
我尝试了什么:
i尝试谷歌但没有答案
please who can help i want create input field whenever a button is click but i don't kown how do that.
What I have tried:
i try to google it out but no answer yet
推荐答案
嗨alertfrancis
,
您可以使用createElement
和appendChild
执行此操作的JavaScript方法。
Hialertfrancis
,
You can usecreateElement
andappendChild
JavaScript methods to do this.
<div id="dynamicCheck">
<input type="button" value="Create Element" onclick="createNewElement();"/>
</div>
<div id="newElementId">New inputbox goes here:</div>
JavaScript
==========
JavaScript
==========
<script type="text/JavaScript">
function createNewElement() {
// First create a DIV element.
var txtNewInputBox = document.createElement('div');
// Then add the content (a new input box) of the element.
txtNewInputBox.innerHTML = "<input type='text' id='newInputBox'>";
// Finally put it where it is supposed to appear.
document.getElementById("newElementId").appendChild(txtNewInputBox);
}
</script>
请在网上阅读更多内容。
Please read more on them on the net.
这篇关于如何通过单击按钮创建输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文