2012-02-22 11 views
1

Javascriptをは[] table.cell。のinnerTextはIEで動作しなくMozillaでは

function test(){ 
var tableToSort = document.getElementById('tblid'); 
    for (i=1; i < tableToSort.rows.length; i++) 
      { 
      alert("result ============> "+tableToSort.cells(iCurCell).innerText); 
      iCurCell = iCurCell + tableToSort.cols; 
      } 
} 

UPPER関数ではない、私はMozillaで

function test(){ 
    var tableToSort = document.getElementById('tblid'); 
     for (i=1; i < tableToSort.rows.length; i++) 
       { 
     alert("result ============> "+tableToSort.rows[iCurCell1].cells[2].textContent); 
       iCurCell = iCurCell + tableToSort.cols; 
       } 
    } 

でそれを変更する必要がありますのでIEではなく、モジラで働きますループの最初のレコードではうまく動作しますが、他の場合はundefinedが出力されます。 IEでは、すべてのレコードが正しく印刷されます。

答えて

0

innerTextプロパティはIEの場合のみです。this pageを参照してください。textContentをIE9を含むほとんどのブラウザに使用してください。

0

あなたが本当にテーブルセル内部textNodeを探す必要があります:内部で あなたのために:

var tcell = tableToSort.rows[iCurCell1].cells[2]; 
var child = tcell.firstChild; 
do { 
    if(child.nodeType == 3) 
     break; 
} while(child = child.nextSibling); 
var textThatYouWant = child.nodeValue; 

これはすべてのブラウザで動作する真のDOMの実装です

関連する問題