---
title: "最精简的复选框(checkbox)全选代码"
author: "sylixj2009"
date: "2010-10-25T16:06:41Z"
tags: []
categories: ["Web前端"]
slug: "checkbox"
draft: false
lastmod: "2010-10-25T16:06:41Z"
id: 793325
url: "https://springcher.iteye.com/blog/793325"
---

<input type=checkbox name=chk>
<input type=checkbox name=chk>
<input type=checkbox name=chk>
<input type=checkbox name=chk>
<input type=checkbox name=chk>
<br>
全选：<input type=checkbox onclick=sel('chk')>
<script language="javascript">
 function sel(a){
  o=document.getElementsByName(a)
  for(i=0;i<o.length;i++)
  o*.checked=event.srcElement.checked
 }
</script>