频道栏目
首页 > 资讯 > JavaScript > 正文

用JavaScript改变table的背景色

17-06-19        来源:[db:作者]  
收藏   我要投稿

用JavaScript改变table的背景色

index.html:

<meta charset="UTF-8" />
<title></title>
<link href="styles/format.css" rel="stylesheet" />
<table>
<caption>
	Itinerary</caption>
<thead>
	<tr>
	<th>
		When</th>
	<th>
		Where</th>
	</tr>
</thead>
<tbody>
	<tr>
	<td>June 9th</td>
	<td>Poratland,<abbr title="Oregon">OR</abbr></td>
	</tr>
	<tr>
	<td>June 10th</td>
	<td>Poratland,<abbr title="Oregon">OR</abbr></td>
	</tr>
	<tr>
	<td>June 11th</td>
	<td>Poratland,<abbr title="Oregon">OR</abbr></td>
	</tr>
</tbody>
</table>
<script src="JS/add.js"></script>

format.css:

body{
    background-color: #fff;
    color: #000;
}

table{
    margin:auto;
    border:1px solid #699;
}

caption{
    margin:auto;
    padding: .2em;
    font-size: 1.2em;
    font-weight: bold;
}

th{
    font-weight: normal;
    font-style: italic;
    text-align: left;
    border:1px dotted #699;
    background-color: #9cc;
    color: #000;
}

th,td{
    width:10em;
    padding: .5em;
    text-align: center;
}
add.js:
function addLoadEvent(func){
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    }else {
        window.onload = function(){
            oldonload();
            func();
        }
    }
}

function stripeTables(){
    if (!document.getElementsByTagName) return false;
    var tables = document.getElementsByTagName("table");
    var odd,rows;
    for(var i=0; i

 

相关TAG标签
上一篇:AMD、CMD、webpack理解
下一篇:Lua表达式
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站