如何使用JavaScript在ASP.NET Web表单上动态添加文本框 [英] How to add textboxes dynamically on a asp.net webform using javascript
本文介绍了如何使用JavaScript在ASP.NET Web表单上动态添加文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想单击按钮即可将文本框动态添加到Web表单.该号码将在文本框中提供.为了更好地理解,下面给出了一个图像:动态文本框
I want to add textboxes dynamically to a web form on the click of a button. The number will be provided in a textbox. For better understanding an image is given below: Dynamic TextBoxes
推荐答案
您需要使用 append()
方法向DOM动态添加新元素.我在这里创建了一个演示以便更好地理解: https://jsfiddle.net/p2hr1a1f/
you need to use append()
method to add new elements dynamically to DOM. I have created a demo for better understanding here : https://jsfiddle.net/p2hr1a1f/
HTML
<input type="text" class="noTxt">
<button class="btnCreate">
Create
</button>
<div class="txtBox-container">
</div>
jQuery
$(document).ready(function(){
$('.btnCreate').on('click', function(){
var txtBox="<input type='text' class='newtxtBox'><br>";
l=$('.noTxt').val();
console.log(l);
for(var i=1;i<=l;i++){
$('.txtBox-container').append(txtBox);
console.log(txtBox);
}
});
});
这篇关于如何使用JavaScript在ASP.NET Web表单上动态添加文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文