为了账号安全,请及时绑定邮箱和手机立即绑定

如图,我想点击第n个li则第n个p和第n个th隐藏,怎么没效果?

如图,我想点击第n个li则第n个p和第n个th隐藏,怎么没效果?

繁星淼淼 2022-12-08 17:13:52
<script> $("ul li:nth-child(n)").click(function(){ $(".id p:nth-child(n)").hide(); $("table tr th:nth-child(n)").hide(); }); </script>
查看完整描述

1 回答

?
www说

TA贡献1775条经验 获得超8个赞

$('ul li').click(function(){    var index = $(this).index()    $('.id p').eq(index).hide()    $('table tr th').eq(index).hide()})

div:nth-child(n)    代表div里面的所有子元素

div:nth-child(2n)    代表div里面的双数元素 0,2,4,6,8,......

div:nth-child(2n+1)   代表div里面的单数元素 1,3,5,7,9,......


查看完整回答
反对 回复 2022-12-10
  • 1 回答
  • 0 关注
  • 97 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号