如何添加,删除按钮中的动态文本框单击asp.net c# [英] How to add, remove the dynamic textbox in button click asp.net c#
本文介绍了如何添加,删除按钮中的动态文本框单击asp.net c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi Team,
如何在按钮单击asp.net c#中添加,删除动态文本框。
请给出如何添加的解决方案,删除按钮中的动态文本框单击asp.net c#
Hi Team,
How to add, remove the dynamic textbox in button click asp.net c#.
Kindly give the solution for How to add, remove the dynamic textbox in button click asp.net c#
推荐答案
你可以简单地使用knockout.js和HTML 。
在你的libs目录中包含以下文件。
jquery-2.1.1.min
knockout-3.2.0
现在你的HTML(或aspx页面)
employeePhone.html
You can simply use knockout.js with HTML.
Include below files to your libs directory.
jquery-2.1.1.min
knockout-3.2.0
Now your HTML(or aspx page)
employeePhone.html
<html>
<head>
<script src="libs/jquery-2.1.1.min.js" type="text/javascript"></script>
<script src="libs/knockout-3.2.0.js" type="text/javascript"></script>
<script src="PhoneModal.js" type="text/javascript"></script>
<script src="PhoneViewModal.js" type="text/javascript"></script>
<script type="text/javascript">
( document )。ready( function (){
ko.applyBindings( new PhoneViewModel());
});
< / script >
< / head >
< 正文 >
< 表格 id = employeeForm name = employeeForm 方法 = POST >
< script id = PhoneTemplate type = text / html >
< div >
< ; span >
< label > 国家/地区代码: < / label >
< input type = text id = txtCountryCode data-bind = value:CountryCode / >
< / span >
< span >
< 标签 > 电话号码: < / label >
< 输入 类型 = text id = txtPhoneNumber data-bind = value:PhoneNumber / < span class =code-keyword>>
< / span >
< 输入 type = button id = btnRemove < span class =code-keyword>>
value =删除data-bind =click:
(document).ready(function(){ ko.applyBindings(new PhoneViewModel()); }); </script> </head> <body> <form id="employeeForm" name="employeeForm" method="POST"> <script id="PhoneTemplate" type="text/html"> <div> <span> <label>Country Code:</label> <input type="text" id="txtCountryCode" data-bind="value:CountryCode" /> </span> <span> <label>Phone Number:</label> <input type="text" id="txtPhoneNumber" data-bind="value:PhoneNumber" /> </span> <input type="button" id="btnRemove"> value="Remove" data-bind="click:
parent.remove/>
< / input > < / div >
< / script >
< div >
< h2 > 员工电话号码< / h2 >
< div data-bind = template:{name:'PhoneTemplate',foreach:PhoneList} >
< / div >
< div >
< 输入 type = 按钮 id = btnAdd >
value =添加另一个data-bind = click:add/>
< / input > < / div >
< / div >
< / form >
< / body >
< / html >
parent.remove" /> </input></div> </script> <div> <h2>Employee Phone Number</h2> <div data-bind="template:{name:'PhoneTemplate', foreach:PhoneList}"> </div> <div> <input type="button" id="btnAdd"> value="Add Another" data-bind="click: add" /> </input></div> </div> </form> </body> </html>
2. PhoneModal.js
2. PhoneModal.js
function Phone(code, number) {
var self = this;
self.CountryCode = ko.observable(code);
self.PhoneNumber = ko.observable(number);
}
3. PhoneViewModal
3. PhoneViewModal
function PhoneViewModel() {
var self = this;
self.PhoneList = ko.observableArray([new Phone("00", "00-00-00")]);
self.remove = function () {
self.PhoneList.remove(this);
};
self.add = function () {
self.PhoneList.push(new Phone("01", "00-00-01"));
};
}
我希望这有助于您了解并创建您的要求。
I hope this will help you to understand and to create your reuirement.
这篇关于如何添加,删除按钮中的动态文本框单击asp.net c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文