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

隐藏行时该怎么优化达到特定行的删除?

隐藏行时该怎么优化达到特定行的删除?

<!DOCTYPE html> <html>     <head>         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />         <title>挑战题</title>      <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>      <style>         table{ border-collapse:collapse;                text-align:center;         }         table th{             font-size:16px;             padding:10px;             font-weight:bold;                      }         table td{             height:30px;             line-height:30px;         }          </style>      <script>          var Stu_fyi=[              {"name":"AA","age":"20","gender":"female","grade":"3","Class":"2"},              {"name":"BB","age":"21","gender":"male","grade":"2","Class":"4"},              {"name":"CC","age":"22","gender":"female","grade":"3","Class":"5"},              {"name":"DD","age":"20","gender":"female","grade":"1","Class":"1"},              {"name":"EE","age":"22","gender":"male","grade":"3","Class":"6"},              {"name":"FF","age":"23","gender":"female","grade":"1","Class":"2"},          ];                    $(function(){              $("a").bind('click',function(){                  if($("#stu a").text()=='显示学生信息'){                                                      $.each(Stu_fyi,function(index,obj){                                          $('#stu').before("<tr><td>"+obj.name+"</td><td>"+obj.age+"</td><td>"+obj.gender+"</td><td>"+obj.grade+"</td><td>"+obj.Class+"</td></tr>");                     $("#stu a").html("隐藏学生信息");                                        })                  }else{                                            $("tr:eq(1),tr:eq(2),tr:eq(3),tr:eq(4),tr:eq(5),tr:eq(6)").remove();                                          $("#stu a").html("显示学生信息");                  }                                                                                  })                                                                                })                          </script>     </head>     <body>         <table border='1'>                   <tr>                 <th>name</th>                 <th>age</th>                 <th>gender</th>                 <th>grade</th>                 <th>class</th>             </tr>             <tr id="stu">                 <td colspan='5' ><a href="#">显示学生信息</a></td>             </tr>                    </table>         <div></div>     </body> </html>
查看完整描述

1 回答

?
捡到一只蝉

TA贡献4条经验 获得超1个赞

  $("a").bind('click',function( e ){
      var $target = $(e.target); // 获取触发事件的目标元素
  }


查看完整回答
反对 回复 2016-05-27
  • 1 回答
  • 0 关注
  • 1130 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信