诡异问题,请教大虾。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<body>
<script language="javascript" type="text/javascript">
document.getElementsByClassName = function(cl)
{
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var j = 0; j < elem.length; j++) {
var classes = elem[j].className;
if (myclass.test(classes)) retnode.push(elem[j]);
}
return retnode;
}
function setCookie(sName,sValue)
{
var cookieString = sName + "=" + escape(sValue);
document.cookie = cookieString;
}
function getCookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var j=0; j < aCookie.length; j++){
var aCrumb = aCookie[j].split("=");
if (escape(sName) == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
function foo(idx)
{
var items = document.getElementsByClassName(idx);
var miniPic = document.getElementById(idx);
for (var j=0; j<items.length; j++)
{
if (getCookie(items[j].getAttribute("id")) == null)
{
miniPic.setAttribute('src', 'jian.png');
items[j].setAttribute('style', 'display:');
setCookie(items[j].getAttribute("id"), "1");
}
else
{
if (getCookie(items[j].getAttribute("id")) == 1) {
miniPic.setAttribute('src', 'jia.png');
items[j].setAttribute('style', 'display:none;');
setCookie(items[j].getAttribute("id"), "0");
} else if (getCookie(items[j].getAttribute("id")) == 0) {
miniPic.setAttribute('src', 'jian.png');
items[j].setAttribute('style', 'display:');
setCookie(items[j].getAttribute("id"), "1");
} else {
alert("error");
}
}
}
}
</script>
<table border="1">
<thead>
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
</tr>
</thead>
<tfoot>
<tr><th></th></tr>
</tfoot>
<tbody>
<tr>
<td><a href="javascript:void(0)"><img id="123456" onclick="foo(this.id)" src="jia.png" /></a></td>
<td>totalName</td>
<td>II</td>
<td>sum</td>
</tr>
<tr class="123456" id="123" style='display:none'>
<td></td>
<td>child1</td>
<td>II</td>
<td>200</td>
</tr>
<tr class="123456" id="124" style='display:none'>
<td></td>
<td>child2</td>
<td>II</td>
<td>300</td>
</tr>
</tbody>
</table>
</body>
</html>
截图00.jpg
( 15.02 KB 下载:14 次 )
最佳答案