天易20—-jquery實現複選框的全選與全不選功能

來源:互聯網
上載者:User

一:1)引進jquery-1.6.4.min.js檔案

2)如下:

a)預設情況:

b)點擊全選後並點擊提交按鈕後:

c)當點擊個別按鈕時:

二:程式碼範例如下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title></title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><script type="text/javascript" src="<%=basePath %>js/jquery-1.6.4.min.js"></script><script type="text/javascript">$(document).ready(function(){  $('#checkedAll').click(function(){  //  if(this.checked){/*對預設是否為選中進行判斷*///  $('[name=checkboxt]:checkbox').attr('checked',true);/*checked為true時為預設顯示的狀態,為true實現全選功能*///  }else{//  $('[name=checkboxt]:checkbox').attr('checked',false);/*false為反選即為全部選功能*///  }//實現全選全不選的另一種方法$('[name=checkboxt]:checkbox').attr('checked',this.checked);/*checked為true時為預設顯示的狀態*/    });    //實現反選功能/*  $('#checkedRev').click(function(){    $('[name=checkboxt]:checkbox').each(function(){  this.checked=!this.checked;  });    });*/    //點擊提交按鈕查看所選複選框的內容  $('#send').click(function(){    var str="你的愛好是:";  $('[name=checkboxt]:checkbox:checked').each(function(){str+=$(this).val()+",";//接收顯示所選複選框的內容});  alert(str);  });  });</script> <style type="text/css">*{padding:10xp;margin:0;}body {padding-left:100px;padding-top:100px;font-size:12px;font-family:"宋體";}</style> </head><body><form action="" method="post">你的愛好是:<input type="checkbox"  id="checkedAll"/>全選/全不選<!-- <input type="checkbox"  id="checkedRev"/>反選 --><br/><input type="checkbox"  name="checkboxt" value="看書"/>看書<input type="checkbox"  name="checkboxt" value="唱歌"/>唱歌<input type="checkbox"  name="checkboxt" value="跳舞"/>跳舞<input type="checkbox"  name="checkboxt" value="運動"/>運動<br/><input type="button" id="send" value="提交"/></form></body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.