[英]JavaScript onclick conditional table cell
我最近遇到了一個問題 ,此后已經解決了。
但是,我現在有另一個問題。 我希望代碼僅切換第二列和第三列中單元格的可見性。
我不知道該如何處理,我對JavaScript的了解很少。
同樣,將第二行和第三行中的所有單元格自動切換為不可見也很好,但不是必須的。
編輯:
為方便起見,我僅將解決方案復制到了先前的問題。
function tableclick(e)
{
e = e || window.event;
var target = e.target || e.srcElement;
while(target != this && (!target.tagName || target.tagName != "TD")) target = target.parentNode;
if( target != this)
{
toggleVis(target)
}
}
function toggleVis(obj)
{
if ( obj.style.fontSize != "0px" )
{
obj.style.fontSize = "0px"
}
else
{
obj.style.fontSize = "16px"
}
}
function tableclick(e)
{
e = e || window.event;
var target = e.target || e.srcElement;
while(target != this && (!target.tagName || target.tagName != "TD")) target = target.parentNode;
if( target != this && (target.cellIndex == 1 || target.cellIndex == 2))
{
toggleVis(target)
}
}
我通過做一些我從未想到會真正起作用的事情來解決了這個問題,但是在那里...
function tableclick(e)
{
var ColNum=1;
if(navigator.userAgent.indexOf("MSIE")!=-1) {
if(event.srcElement.tagName=="TD") {
ColNum+=event.srcElement.cellIndex;
}
}
else {
if (e.target == "[object HTMLTableCellElement]") {
ColNum+=e.target.cellIndex;
}
}
if (ColNum == 2 || ColNum == 3)
{
e = e || window.event;
var target = e.target || e.srcElement;
while(target != this && (!target.tagName || target.tagName != "TD")) target = target.parentNode;
if( target != this)
{
toggleVis(target)
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.