gae利用checkbox进行批量删除 JS常用代码:五行搞定checkbox全选/全不选

来源:互联网 发布:软件开发公司业务 编辑:程序博客网 时间:2024/06/10 11:44

这个东西看上去很容易 ,但是如果有个小细节把握不好的话,那么根本无法完成,那就是request.get_all()的使用。

 

以下是我的代码:

    在template中很简单:admin/infoList.html

{% for info in infos %}

    <form action = "/admin/infos/d" method = "post">

    <input type="checkbox" name="id" value='{{ info.key.id }}'>{{ info.key.id }} :name的值就是前台取的值,vaule是真值

 

{% endfor %}

 

    <input type="submit" name='submit' value="批量删除">

    </form>

 

前台:('/admin/infos/d', Infosd),路径指向的函数 def

 

 

class Infosd(webapp.RequestHandler):

    def post(self):

 

    infoId = self.request.get_all('id')#这里的get_all是关键,如果用的是get的话他只会一次取一个删除,而且不是List,不能循环

                for i in infoId:

 

                  info = Info.get_by_id(int(i))

                  info.delete()

 

    infos = Info.all()

 

    template_values = {

    'infos':infos,

    'infoId':id

    }

path = os.path.join(os.path.dirname(__file__), 'admin/infoList.html')

self.response.out.write(template.render(path, template_values))

 

 

 

 

 

JS常用代码:五行搞定checkbox全选/全不选 收藏

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>无标题文档</title>
  6. <style type="text/css">
  7. p {margin:0;font-size:12px;line-height:26px;}
  8. </style>
  9. <script type="text/javascript">
  10. function check_all(obj,cName)
  11. {
  12.     var checkboxs = document.getElementsByName(cName);
  13.     for(var i=0;i<checkboxs.length;i++){checkboxs[i].checked = obj.checked;}
  14. }
  15. </script>
  16. </head>
  17.  
  18. <body>
  19. <p><input type="checkbox" name="all" onclick="check_all(this,'c')" />全选/全不选</p>
  20. <p><input type="checkbox" name="c" value="" /></p>
  21. <p><input type="checkbox" name="c" value="" /></p>
  22. <p><input type="checkbox" name="c" value="" /></p>
  23. <p><input type="checkbox" name="c" value="" /></p>
  24. </body>
  25. </html>