search
Homephp教程php手册javascrip全选效果之学习笔记

javascrip全选效果之学习笔记

Jun 13, 2016 am 10:16 AM
javascripselect allstudyIusOpenBundleEffecthourofnotesautomaticpage

我要做的效果就是当我们打开页面时就自动把所有checkbox选中,原理是:先获取所有type为\'input \'的元素,然后各全选的那个选项添加点击事件。如果全选项被经被选中,则通过循环使得每个元素的\'checked\'属性变为true,否则变成false.

document.getElementById(' ')是某个元素的id特性来获取某个指定的元素,返回的是一个对象。document.getElementById(' ') 是根据控件TAG(type属性)获取这个控件对象,返回的是一个对象数组;

要实现一个全选的效果,得先定义一组选项。

 代码如下 复制代码


 

全选


    

    

    

    

    

    

    

 

接下利用Javascript来实现效果。教程中的效果是只能点全选时全部选中,如果再点全选就不能全部反选,这里我通过自己的理解,加入了这个功能

 代码如下 复制代码

个人感觉此种方法还是有所欠缺,他会将页面中所有的类型为input的选中.现在我们写了一个利用点击事件来进行全选也反选效果。

 代码如下 复制代码




1





这样如果结合php程序也实现删除功能我们只需要把获取的字符串以post或get方式提供就可以了,下面来看get方式提供。

 代码如下 复制代码

//批量删除   
//na 是name  
function checkSubmit(na,url)
{
 
    var str = '';
    for(var i=0;i     {
          if(document.getElementsByName(na)[i].checked){
            if(str=='') str += document.getElementsByName(na)[i].value;
            else str += ',' + document.getElementsByName(na)[i].value;
          }
    }
    if(str=='')
    {
        alert('你没选择任何内容!');
        return false;
    }
    else
    {
        location=url+"?id="+str+"&action=delall";
    }
}

在php程序中我们就要以

 代码如下 复制代码

$a = $_GET['id'];

然后利用where id in( $a ) 即可实现删除了哦,这也算是一简单php教程吧,有需要的朋友可学习交流。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software