<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<style type="text/css">
*{margin:0;padding:0;} 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;
}
td,th{
width:10em;
padding:.5em;
}
.intro{background:orange;}
.intro1{border:1px solid #000}
</style>
</head>
<body> <table>
<caption class="intro1">Itinerary</caption>
<thead>
<tr>
<th>when</th>
<th>where</th>
</tr>
</thead>
<tbody>
<tr>
<td>June 9th</td>
<td>Portland, <abbr title="Orange">or</abbr></td>
</tr>
<tr>
<td>June 10 th</td>
<td>Seattle , <abbr title="washington">WA</abbr></td>
</tr>
<tr>
<td>June 12th</td>
<td>Sacramento,<abbr title="">CA</abbr></td>
</tr>
</tbody>
</table>
<script type="text/javascript">
var caption = document.getElementsByTagName("caption");
for(var i=0; i<caption.length; i++){
caption[i].className = " intro";
}
function stripeTables(){
var tables = document.getElementsByTagName("table");
for(var i=0; i<tables.length; i++){
var odd = false;
var rows = tables[i].getElementsByTagName("tr");
for(var j=0; j<rows.length; j++){
if(odd == true){
rows[j].style.backgroundColor = "orange";
odd = false;
}
else{
odd = true;
}
}
}
}
stripeTables() function highlightRows(){
var rows = document.getElementsByTagName("tr");
for(var i=0; i<rows.length; i++){
rows[i].onmouseover = function(){
this.style.fontWeight = "bold";
}
rows[i].onmouseout = function(){
this.style.fontWeight = "normal";
}
}
}
highlightRows()
</script> </body>
</html>
caption[i].className = " intro"; 这里我加了空格了啊?
然后对.intro1 进行样式修改.但是无效啊?
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<style type="text/css">
*{margin:0;padding:0;} 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;
}
td,th{
width:10em;
padding:.5em;
}
.intro{background:orange;}
.intro1{border:1px solid #000}
</style>
</head>
<body> <table>
<caption class="intro1">Itinerary</caption>
<thead>
<tr>
<th>when</th>
<th>where</th>
</tr>
</thead>
<tbody>
<tr>
<td>June 9th</td>
<td>Portland, <abbr title="Orange">or</abbr></td>
</tr>
<tr>
<td>June 10 th</td>
<td>Seattle , <abbr title="washington">WA</abbr></td>
</tr>
<tr>
<td>June 12th</td>
<td>Sacramento,<abbr title="">CA</abbr></td>
</tr>
</tbody>
</table>
<script type="text/javascript">
var caption = document.getElementsByTagName("caption");
for(var i=0; i<caption.length; i++){
caption[i].className = " intro";
}
function stripeTables(){
var tables = document.getElementsByTagName("table");
for(var i=0; i<tables.length; i++){
var odd = false;
var rows = tables[i].getElementsByTagName("tr");
for(var j=0; j<rows.length; j++){
if(odd == true){
rows[j].style.backgroundColor = "orange";
odd = false;
}
else{
odd = true;
}
}
}
}
stripeTables() function highlightRows(){
var rows = document.getElementsByTagName("tr");
for(var i=0; i<rows.length; i++){
rows[i].onmouseover = function(){
this.style.fontWeight = "bold";
}
rows[i].onmouseout = function(){
this.style.fontWeight = "normal";
}
}
}
highlightRows()
</script> </body>
</html>
caption[i].className = " intro"; 这里我加了空格了啊?
然后对.intro1 进行样式修改.但是无效啊?
解决方案 »
- alert之后,后面的代码才正确执行
- 这是一个网络摄像机的WEB页,看不懂脚本,请高手来解答?
- 请问一个javascript的打印问题!
- 求救:点击图片按钮,在表格中显示内容 谢谢
- 关于正则表达式
- $(document).ready(function()....这个什么意思?
- 使用J s来实现 web 版的 类似于 安卓桌面的 左右滑动特效,在线等
- 请问谁知道关于scriptlet和object的详细学习网址
- 100分求一个小功能实现的js代码!!!
- IIS配置后用127.0.0.1:98/index.html能打开,但是用本机IP打开却报错:FATAL:LICENSE ERROR
- 关于jquery插件
- 帮我分析下这段代码..
可以document.getElementsByTagName("caption").className="intro introl";
css中是可以这样写的。class="class1 class2"
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<style type="text/css">
*{margin:0;padding:0;} 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;
}
td,th{
width:10em;
padding:.5em;
}
.intro{background:orange;}
.intro1{border:1px solid #000}
.odd{background:yellow;}
.title{background:yellow;}
</style>
</head>
<body> <h1>我是标题!</h1> <em>我的重要的!</em> <p>我是对的</p> <table>
<caption>Itinerary</caption>
<thead>
<tr>
<th>when</th>
<th>where</th>
</tr>
</thead>
<tbody>
<tr>
<td>June 9th</td>
<td>Portland, <abbr title="Orange">or</abbr></td>
</tr>
<tr>
<td>June 10 th</td>
<td>Seattle , <abbr title="washington">WA</abbr></td>
</tr>
<tr>
<td>June 12th</td>
<td>Sacramento,<abbr title="">CA</abbr></td>
</tr>
</tbody>
</table>
<input type="button" onclick="findTextNode();">
<script type="text/javascript">
/* function findTextNode() {
var ps = document.getElementsByTagName('p');
for (var index = 0; index < ps.length; index++) {
alert(ps[index].childNodes[0].nodeType);
alert(ps[index].childNodes[0].nodeValue);
}
} function addClass(element,value){
if(!element.className){
element.className = value;
}
else{
newClassName = element.className;
newClassName+= " ";
newClassName+= value;
element.className = newClassName;
}
}
function title() {
var titles = document.getElementsByTagName("h1");
for(var i=0; i<titles.length; i++){
var elem = getNextElement(titles[i].nextSibling)
addClass(elem,"title")
}
}
function getNextElement(node){
if(node.nodeType == 1){
return node;
}
if(node.nextSibling){
return getNextElement(node.nextSibling);
}
}
title()
/*
function getNextElement(node){
if(node.nodeType == 1){
return node;
}
if(node.nextSibling){
return getNextElement(node.nextSibling);
}
}
function styleHeaderSiblings(){
var headers = document.getElementsByTagName("h1");
for(var i=0; i<headers.length; i++){
var elem = getNextElement(headers[i].nextSibling);
addClass(elem,"title");
}
}
styleHeaderSiblings()
*/ var caption = document.getElementsByTagName("caption").className = "intro";
function stripeTables(){
var tables = document.getElementsByTagName("table");
for(var i=0; i<tables.length; i++){
var odd = false;
var rows = tables[i].getElementsByTagName("tr");
for(var j=0; j<rows.length; j++){
if(odd == true){
rows[j].style.backgroundColor = "orange";
odd = false;
}
else{
odd = true;
}
}
}
}
stripeTables() function highlightRows(){
var rows = document.getElementsByTagName("tr");
for(var i=0; i<rows.length; i++){
rows[i].onmouseover = function(){
this.style.fontWeight = "bold";
}
rows[i].onmouseout = function(){
this.style.fontWeight = "normal";
}
}
}
highlightRows() </script> </body>
</html>
2楼的方法我试了.无效啊
for(var i=0; i<caption.length; i++){
caption[i].className = "intro1 intro";
}