我已经尝试了以下代码,但从给定的示例中可以看出,它不适用于偶数列。我无法确定问题所在。请帮助我进行必要的更正。我只是一个热心的学习者。
CSS:
.foo{visibility:hidden};
.faa{visibility:hidden};
.fii{visibility:hidden};
JavaScript:
var toggle = function (action) {
var trs = document.getElementById('bar').getElementsByTagName('tr'),
trs_count = trs.length,
needed = [],
total = 0,
pattern = /faa|foo|fii\b/g,
initial= 'show';
for (i=0; i<trs_count; i++) {
var tds = trs[i].getElementsByTagName('td'),
tds_count = tds.length;
for (j=0; j<tds_count; j++) {
if (pattern.exec(tds[j].className)) {
needed.push(tds[j]);
total++;
}
}
}
toggle = function (action) {
if (this.display == null) {
this.display = initial;
}
if (action == null) {
this.display = (this.display == 'hide') ? 'show' : 'hide';
}
else {
this.display = action;
}
for (i=0; i<total; i++) {
if (this.display == 'show') {
needed[i].style.visibility = 'hidden';//changed from display = 'block';
}
else {
needed[i].style.visibility = 'visible';//changed from display = 'none';
}
}
return true;
}
return toggle();
}
HTML:
<DIV ALIGN="center" style="display:none">
<!-- used the following patterns. but of no use
/f(\w)\1/g, //f(\w)\1/g, /\bfoo\b/g, /faa|foo|fii\b/g, -->
</DIV>
<TABLE id="bar" class="reg" ALIGN="CENTER" BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH="90%">
<TR ALIGN="left" VALIGN="middle">
<TD width="20%"> URL of Site</TD>
<TD width="20%">User I
<span onclick="toggle()">D</span> // the event handler
/Nickname</TD>
<TD ALIGN="left" width="10%" align="center" nowrap>xxx</TD>
<TD width="30%">Clue</TD>
<TD width="20%">Other Information</TD>
</TR>
<TR ALIGN="left" VALIGN="middle">
<TD>xxxxxxxxxxxxx</TD>
<TD>xxxxxxxxxxxxx</TD>
<td class="foo">xxxxxxxxx</td>
<TD class="faa">xxxxxxxxx</TD>
<TD class="fii">xxxxxxxxxx</TD>
</TR>
<TR ALIGN="left" VALIGN="middle">
<TD>xxxxxxxxxxxxx</TD>
<TD>xxxxxxxxxxxxx</TD>
<td class="foo">xxxxxxxxx</td>
<TD class="faa">xxxxxxxxx</TD>
<TD class="fii">xxxxxxxxxx</TD>
</TR>
<TR ALIGN="left" VALIGN="middle">
<TD>xxxxxxxxxxxxx</TD>
<TD>xxxxxxxxxxxxx</TD>
<td class="foo">xxxxxxxxx</td>
<TD class="faa">xxxxxxxxx</TD>
<TD class="fii">xxxxxxxxxx</TD>
</TR>
</TABLE>
演示:小提琴