作者:werwd2_736 | 来源:互联网 | 2023-01-30 21:26
HTML代码
- Anthropology Department
- Anthropology Faculty Collections
- Shared Collections
- Center for Research on Vermont
- Collections for Testing
- Geology Department
jQuery的
jQuery(function($){
var $ul = $('ul');
$ul.find('li[parent-id]').each(function () {
$ul.find('li[parent-id=' + $(this).attr('li-id') + ']').wrapAll('
').parent().appendTo(this)
});
});
//to get li-id on double click
$('#orgCat li').dblclick(function(){
alert($(this).attr('li-id'));
})
问题是当双击'li'元素时它也显示父母'li-id'但它应该只返回当前列表'li-id'.的jsfiddle
1> Prashant Shi..:
您需要使用e.stopPropagation
停止事件冒泡.
$('#orgCat li').dblclick(function(e){
e.stopPropagation();
alert($(this).attr('li-id'));
});
请查看此链接以获取更多信息.