在asp.net中ListView的交替背景顏色實現
GridView的處理得較多,ListView可以這樣實現,
只一行程式碼:
">另外還有直接用js處理整個頁面中所有tr的交替色:
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <title>網頁特效|Linkweb.cn/Js|---全選並改變TR顏色title>
- <mce:script language="JavaScript" type="text/javascript" for="checkbox" event="onclick"><!--
- tr_bgcolor(this);
- // -->mce:script>
- <mce:script language="JavaScript" type="text/javascript"><!--
- function tr_bgcolor(c){
- var tr = c.parentNode.parentNode;
- tr.rowIndex % 2 == 0 ? tr.style.backgroundColor = c.checked ? '#add6a6' : '#eee' : tr.style.backgroundColor = c.checked ? '#add6d6' : '';
- }
- function selall(obj){
- for (var i=0; i<obj.form.elements.length; i++)
- if (obj.form.elements[i].type == 'checkbox' && obj.form.elements[i] != obj){
- obj.form.elements[i].checked = obj.checked;
- tr_bgcolor(obj.form.elements[i]);
- }
- }
- // -->mce:script>
- head>
- <body>
- <form id="form1" name="form1" method="post" action="">
- <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#888888">
- <tr><td><input name="selectall" type="checkbox" value="全選" onclick="selall(this)" />td>tr>
- <tr><td>
- <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
- <tr style="background-color:#eee;" mce_style="background-color:#eee;"><td width="6%"><input type="checkbox" name="checkbox" />td><td width="94%">***********************td>tr>
- <tr><td><input type="checkbox" name="checkbox" />td><td>***********************td>tr>
- <tr style="background-color:#eee" mce_style="background-color:#eee"><td><input type="checkbox" name="checkbox" />td><td>***********************td>tr>
- <tr><td><input type="checkbox" name="checkbox" />td><td>***********************td>tr>
- <tr style="background-color:#eee" mce_style="background-color:#eee"><td><input type="checkbox" name="checkbox" />td><td>***********************td>tr>
- <tr><td><input type="checkbox" name="checkbox" />td><td>***********************td>tr>
- <tr style="background-color:#eee" mce_style="background-color:#eee"><td><input type="checkbox" name="checkbox" />td><td>***********************td>tr>
- <tr><td><input type="checkbox" name="checkbox" />td><td>***********************td>tr>
- <tr style="background-color:#eee" mce_style="background-color:#eee"><td><input type="checkbox" name="checkbox" />td><td>***********************td>tr>
- table>
- td>tr>
- table>
- form>
- body>
- html>
或
- nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>表格行tr顏色交替title>
- <mce:style><!--
- #ab{border-collapse:collapse;width:800px;margin:10px auto;}
- #ab td{border:1px solid #ccc;border-top:none;padding:4px;text-align:center;}
- .tr1{background-color:#eee;color:red;}
- .tr2 {background-color:#ccc;color:blue;}
- -->mce:style><style mce_bogus="1">#ab{border-collapse:collapse;width:800px;margin:10px auto;}
- #ab td{border:1px solid #ccc;border-top:none;padding:4px;text-align:center;}
- .tr1{background-color:#eee;color:red;}
- .tr2 {background-color:#ccc;color:blue;}style>
- <mce:script type="text/javascript"><!--
- function colortd(ob) {
- obob=ob.rows;
- for(var i=0;i<ob.length;i++) {
- if(i%2) ob(i).className="tr1";
- else ob(i).className="tr2";
- }
- }
- // -->mce:script>
- head>
- <body onload="colortd(ab)">
- <table id="ab">
- <tr><td>hang------------1td>tr>
- <tr><td>hang------------2td>tr>
- <tr><td>hang------------3td>tr>
- <tr><td>hang------------4td>tr>
- table>
- body>
- html>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-627814/,如需轉載,請註明出處,否則將追究法律責任。