Javascript 如何防止最后一个li的点击事件触发?

Javascript 如何防止最后一个li的点击事件触发?,javascript,jquery,onclick,html-lists,Javascript,Jquery,Onclick,Html Lists,但这是行不通的。如果遇到相同的问题,请张贴您的答案 提前感谢 它应该代替选择器字符串中的最后一个子项 $(document).on("click", "ul li:not(last-child)", function (e) { //do something } $(文档)。在(“单击”,“ul li:not(:last child)”,函数(e){ console.log('clicked'); }) 试验 试验 试验 它应该是选择器字符串中的最后一个子项 $(document).on

但这是行不通的。如果遇到相同的问题,请张贴您的答案

提前感谢

它应该代替选择器字符串中的最后一个子项

$(document).on("click", "ul li:not(last-child)", function (e) {
//do something
}
$(文档)。在(“单击”,“ul li:not(:last child)”,函数(e){
console.log('clicked');
})

  • 试验
  • 试验
  • 试验
它应该是选择器字符串中的
最后一个子项

$(document).on("click", "ul li:not(last-child)", function (e) {
//do something
}
$(文档)。在(“单击”,“ul li:not(:last child)”,函数(e){
console.log('clicked');
})

  • 试验
  • 试验
  • 试验

您也可以通过
li:not(:last)

$(文档)。在(“单击”,“ul li:not(:last)”,函数(e){
警报()
})

  • 试验
  • 试验
  • 试验

您也可以通过
li:not(:last)

$(文档)。在(“单击”,“ul li:not(:last)”,函数(e){
警报()
})

  • 试验
  • 试验
  • 试验

它现在也在触发$(文档)。在(“单击“,”.ul-li:not(:last child),ul.active),函数(e){}:(:(@DAon:where is
,ul.active
?@DAon:它们都按预期工作…您可以检查它现在也触发$(文档)的代码段。在(“单击“,”.ul-li:not(:last child),ul.active”,函数(e){}:(:(@DAon:where is
,ul.active
?@DAon:where is
,ul.active都按预期工作……您可以检查代码段
$(document).on("click", "ul li:not(:last-child)", function (e) {
   //do something
})