$('#input').change(function () {
console.log($('#add'));
value = this.value;
if (this.value){
$('#add').append("<a name='key' class='btn btn-success fa fa-close'>"+this.value+"</a>");
}
});
$(document).on('click','a[name="key"]',function () {
console.log('点击了');
console.log(this);
this.remove();
});
本文介绍如何使用jQuery实现元素的动态添加和移除功能。通过监听输入框的改变事件,将输入值添加到页面中,并为每个添加的元素绑定点击事件以便于移除。该方法适用于创建可交互的用户界面,如标签云或动态选项列表。
1706

被折叠的 条评论
为什么被折叠?



