У меня есть функция javascript (function toggleTree (theRow)), где строка передается этой функции из ячейки в таблице onclick.
<tr class="rowWhite"><td style="text-align:center"><img class="expand" alt="" src="images/plus.jpg"onclick="toggleTree(this.parentNode.parentNode);" />
Функция Toggle tree приведена ниже.
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 из любого браузера?
Вероятно, вы получаете текстовый индекс в других браузерах, чем IE
Как насчет чего-то вроде
window.onload=function() {
var expImg = document.querySelectorAll("img.expand"); // for example
console.log(expImg)
for (var i=0;i<expImg.length;i++) {
expImg[i].onclick=function() {
var exp = this.className == "expand";
this.className=exp?"collapse":"expand";
this.setAttribute("alt",this.className);
this.src=exp?"images/minus.jpg":"images/plus.jpg";
// here you can do something with the row
}
}
}