且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery Cant删除li一旦添加

更新时间:1970-01-01 07:59:12

由于浏览器在读取您的JavaScript代码时,动态添加的li不在DOM中,因此无法找到它.而是将处理程序添加到父级,然后像这样监听a:

Cause when the browser is reading your javascript code the dynamically added li isn't in the DOM, so it can't find it. Instead add the handler to the parent, and listen for the a like this:

$('#cblist').on('click', 'a', function(){
    $(this).parent('li').remove();
    return false;
});

提琴: http://jsfiddle.net/43nWM/3/