我有一個JavaScript函數(函數toggleTree(theRow)),其中行從表中的單元格傳遞給此函數onclick。Row.cells [0] .firstChild在IE和FF中返回不同的值。
<tr class="rowWhite"><td style="text-align:center"><img class="expand" alt="" src="images/plus.jpg"onclick="toggleTree(this.parentNode.parentNode);" />
切換樹狀函數如下。
function toggleTree(theRow)
{
var imgEl = theRow.cells[0].firstChild;
if (theRow.cells[0].firstChild.className == "expand")
{
theRow.cells[0].firstChild.className="collapse";
theRow.cells[0].firstChild.src="images/minus.jpg";
alert(theRow.cells[0].firstChild.className);
alert(theRow.cells[0].firstChild.src);
return "expand";
}
else
{
theRow.cells[0].firstChild.className="expand";
theRow.cells[0].firstChild.src="images/plus.jpg";
alert(theRow.cells[0].firstChild.className);
alert(theRow.cells[0].firstChild.src);
return "collapse";
}
}
theRow.cells的值[0] .firstChild.className和theRow.cells [0] .firstChild.src是在IE和Firefox不同,由於其,該函數不會在FF工作,但它在IE中工作。我如何從任何瀏覽器中將值傳入jsfunction?
你必須有一些空白你不顯示。也緩存你的對象,並在結束後放置一個空間「在src – mplungjan
定義」不同「?每個返回什麼值? –
可能重複[element.firstChild返回'
mplungjan