JS中checkbox組件的使用

來源:互聯網
上載者:User

標籤:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>示範checkbox功能</title>
<link rel="stylesheet" type="text/css" href="table.css">/*這裡寫了table中顏色,等的屬性*/
<script type="text/javascript">
var cName;
function trColor(){/*這個函數是設定表格中奇數行與偶數行的顏色差別 */
var Tb=document.getElementById("mailTable");/* 一般而言如果id這個屬性值是唯一的,所以一般設定一個id屬性值 */
var srow=Tb.rows;
for(var i=1;i<srow.length;i++){
if(i%2==1){
srow[i].className="one";
}
else{
srow[i].className="two";
}
srow[i].onmouseover=function(){
cName=this.className;
this.className="over";
}
srow[i].onmouseout=function(){
this.className=cName;
}
}
}
onload=trColor;
/* 這裡寫成onload=trColor();是指的調用trColor這個函數,而上面那樣寫是將這個函數賦給onload */
function delMail(){
var cbox=document.getElementsByName("mail");
/* 如果是按順序刪除的話就會出現bug---連著刪幾個選項就會發現問題,倒序刪除會避免發生這樣的問題*/
for(var i=cbox.length-1;i>=0;i--){
if(cbox[i].checked){
var obj=cbox[i];
while(obj.nodeName!="TR"){
obj=obj.parentNode;
}
var oTr=obj;
obj.parentNode.removeChild(oTr);
}
}
trColor();
}
</script>
</head>
<body>
<h1>示範table和checked組件</h1>
<table id="mailTable">
<tr>
<th>全選</th>
<th>寄件者</th>
<th>郵件標題</th>
<th>附件</th>
</tr>
<tr>
<td><input type="checkbox" name="mail"></td>
<td>張三</td>
<td>郵件1標題</td>
<td><a href="#">附件1</a>,附件2</td>
</tr>
<tr>
<td><input type="checkbox" name="mail"></td>
<td>張三</td>
<td>郵件2標題</td>
<td><a href="#">附件3</a>,附件4</td>
</tr>
<tr>
<td><input type="checkbox" name="mail"></td>
<td>張三</td>
<td>郵件3標題</td>
<td><a href="#">附件5</a>,附件6</td>
</tr>
<tr>
<td><input type="checkbox" name="mail"></td>
<td>張三</td>
<td>郵件4標題</td>
<td><a href="#">附件7</a>,附件8</td>
</tr>
<tr>
<td><input type="checkbox" name="mail"></td>
<td>張三</td>
<td>郵件標5題</td>
<td><a href="#">附件9</a>,附件10</td>
</tr>
</table>
<input type="button" value="刪除郵件" onclick="delMail();">

</body>
</html>

---------------------------------------------------------

@CHARSET "UTF-8";
table{
border: 1px solid #00ffff;
width:500px;
border-collapse:collapse;
}
td{
border: 1px solid #00ffff;
}
.one{
background-color:#ffff00;
}
.two{
background-color:#c6baef;
}
.over{
background-color:#ffffff;
}

JS中checkbox組件的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.