insertAfter - find - on() - 不起作用 [英] insertAfter - find - on() -- not working
问题描述
我想,我已经设置好了,但它仍然不工作 - 我正在用 我的html是: 它插入的很好,但我无法删除新添加的元素(警报不会触发)。为什么是这样? 非常感谢 使用 i think, i have all set, but it is still not working - i am appending new html element my html is: it is inserting well, but i cannot delete the newly added element (alert is not firing). why is this? thanks a lot The Use
这篇关于insertAfter - find - on() - 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! X $ c附加新的html元素
input
$ c>删除标志。如果我点击新添加的 X
符号,应该删除新添加的输入。我做的是:
$ b $ pre $ function addmore(){
$('< input type =filename ='bild []/>< a class =del> X< / a>< br />')。 ('click',function(){
alert('test');
});
}
< a href =javascript:addmore()>添加更多< / a>
< p id =more>< / p>
< a class =del>
元素是匹配元素集合的一部分,因此不会被拾取。
.filter()
('。del')。on('click',function(){}。 ...});
input
with X
delete sign. if i click on that newly added X
sign, the newly added input should be deleted. what i did is: function addmore(){
$('<input type="file" name="bild[]"/> <a class="del">X</a> <br/>').insertAfter('#more').find('.del').on('click', function(){
alert('test');
});
}
<a href="javascript:addmore()"> add more </a>
<p id="more"></p>
.find()
function looks for elements that are inside the current set of matched elements, but doesn't include those matched elements. Your <a class="del">
element is part of the set of matched elements so won't be picked up..filter()
instead:....filter('.del').on('click', function() {...});