将 <li> 添加到 <ul> 并删除附加到 <ul> 的 <li>
Add <li> to <ul> and remove <li> that is appended to <ul>
$(document).ready(function()
{
$(".males-input").on("click",function()
{
$(".rform .males-list").append('<li><img src="icon/delete.png" title="REMOVE" NAME class="delete-input"/><input type="text" /></li>');
});
});
这是我添加的查询 <li>
我想要的是,如果我单击附加到 <ul>
的 <img>
,它应该删除...
请帮忙...
您需要使用事件委托:
$('ul.males-list').on('click','.delete-input',function(){
$(this).parent().remove();
});
使用这个
$('ul .delete-input').click(function(){
$(this).closest('li').remove();
});
$(document).ready(function()
{
$(".males-input").on("click",function()
{
$(".rform .males-list").append('<li><img src="icon/delete.png" title="REMOVE" NAME class="delete-input"/><input type="text" /></li>');
});
});
这是我添加的查询 <li>
我想要的是,如果我单击附加到 <ul>
的 <img>
,它应该删除...
请帮忙...
您需要使用事件委托:
$('ul.males-list').on('click','.delete-input',function(){
$(this).parent().remove();
});
使用这个
$('ul .delete-input').click(function(){
$(this).closest('li').remove();
});