使用jquery删除动态创建的文本框
我在点击按钮时动态创建文本框。我想知道用另一个按钮点击来删除文本框 HTML使用jquery删除动态创建的文本框,jquery,html,textbox,Jquery,Html,Textbox,我在点击按钮时动态创建文本框。我想知道用另一个按钮点击来删除文本框 HTML <table class="table-fill tbfill"> <thead> <tr> <th class="text-left" runat="server">Screen Name</th> <th class="text-left" runat="server">Seats Av
<table class="table-fill tbfill">
<thead>
<tr>
<th class="text-left" runat="server">Screen Name</th>
<th class="text-left" runat="server">Seats Available</th>
<th class="text-left"></th>
</tr>
</thead>
</table>
<input id="btnAdd" type="button" value="ADD"/>
屏幕名称
有座位吗
jQuery
$("#btnAdd").bind("click", function ()
{
$("tbody.addScreen").append('<tr id="row0">' +
'<td class="text-left" name="screenName"> <input id="screenNameTextBox"/> </td>' +
'<td class="text-left"> <input id="seatsAvlTextBox" name="seatsAvl" /> </td>' +
'<td class="text-left"> <input type="button" value="Remove" id=Removebtn/> </td>' +
'</tr>');
});
$(“#btnAdd”).bind(“单击”,函数()
{
$(“tbody.addScreen”).append(“”+
' ' +
' ' +
' ' +
'');
});
我这里有一个删除按钮。当我点击按钮时,我需要从相应的行中删除文本框。如何执行此操作?您将有许多项具有相同的ID
Removebtn
,row0
,屏幕名文本框
等,这是不正确的。改用类
改变
<input type="button" value="Remove" id=Removebtn/>
然后,您将能够使用事件委派为所有这些按钮分配一个处理程序。例如,此代码将在单击按钮时删除整行:
$(document).on('click', '.RemoveBtn', function() {
$(this).closest('tr').remove();
});
这是你的电话号码
如果只想删除文本框,请使用:
$(document).on('click', '.RemoveBtn', function() {
$(this).closest('tr').find('input[type="text"]').remove();
});
你可以像下面这样做。希望这对你有帮助
$('.tbfill').on('click', '#RemoveBtn', function() {
$(this).closest('tr').find('input').remove();
})
如果要删除整行,请使用
$(this).closest('tr').remove()
。如果只想删除文本框
$(document).on('click', '.RemoveBtn', function() {
$(this).closest('tr').find("input:text").remove();
});
您将有许多项目具有相同的ID
row0
,Removebtn
,这是不正确的。改用类。@YeldarKurmangaliyev:你能给我举个例子吗?它也会删除按钮。
$(document).on('click', '.RemoveBtn', function() {
$(this).closest('tr').find("input:text").remove();
});