再次寻求专家意见,如何使用jquery删除动态元素?我目前正在使用具有添加和删除新部分功能的表单的php页面。现在,当我尝试使用jquery删除新添加的部分时,我遇到了问题。由于超链接不会被触发。
HTML页面:
<div class="form-group">
<label class="control-label col-md-4">File upload</label>
<div class="col-md-6">
<input type="file" />
<textarea required placeholder="Description of the document" class="form-control" name="description-of-incident" id="description-of-incident" rows="2"></textarea>
<div class="help-block with-errors"></div><br />
<a href="javascript:void(0);" id="addanother">Add another</a>
</div>
</div>
<div id="container">
</div>
这是我使用的jQuery:
$(document).ready(function() {
$('input[type="radio"]').click(function() {
if($(this).attr('id') == 'peopleinvolvedyes') {
$('#involvement-section').show();
}
else {
$('#involvement-section').hide();
}
});
$("#addanother").click(function(){
$("#container").append('<div class="form-group"><label class="control-label col-md-4">File upload</label><div class="col-md-6"><input type="file" /><textarea required placeholder="Description of the document" class="form-control" name="description-of-incident" id="description-of-incident" rows="2"></textarea><div class="help-block with-errors"></div><a href="javascript:void(0);" class="remove-document-upload">Remove</a></div></div>');
});
$(".remove-document-upload").click(function(){
alert("dasdasdas");
//$(this).closest('.addanother').remove();
});
});
每当我单击“删除”超链接时,jquery函数都不会触发。
评论和建议受到高度赞赏。
谢谢,Nhoyti
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句