2010-09-15 55 views
0
function highlightRow(searchRow) 
{      
     if(searchRow != null) 
     { 
     var oRows = document.getElementById('Table').getElementsByTagName('tr'); 
     //use row number to highlight the correct HTML row. 
     var lastTwo = searchRow; 
     lastTwo = lastTwo.slice(-2); //extract last two digits   

     oRows[lastTwo].style.background="#90EE90"; 
     }  
} 

我得到了100行的分页。JavaScript如何解释索引?

当searchRow返回55时,突出显示第55行。
当searchRow返回177时,我突出显示第77行,因此为切片函数。

现在问题:
当searchRow返回03或201时,oRows []上的索引不起作用。

这是为什么?

迷惑了我更多的时候我硬编码“03”,它的工作:

oRows[03].style.background="#90EE90"; 

任何深入了解如何工作的?

jQuery是否有这个问题?

谢谢。

+1

'的jQuery '**是** JavaScript,但反之亦然。 – 2010-09-15 19:06:36

回答

2

你处理当前的字符串,你在这里需要一个整数,像这样:

oRows[parseInt(lastTwo, 10)].style.background = "#90EE90"; 

You can give it a try here

做一个准确的测试,看看它在行动,你会看到这个作品:

oRows[03].style.background="#90EE90"; 

(什么现在居然发生)不:

oRows["03"].style.background="#90EE90"; 
+0

明白了,谢谢。 – 2010-09-15 20:44:39