2012-05-27 90 views
0

我有一個應該從文件中讀取到一個變量檢查JavaScript變量的內容

我想知道的讀取正確性,並想知道是否有什麼辦法,我可以檢查功能上傳操作完成後變量的內容。

function handleFileSelect(evt) { 
    var files = evt.target.files; // FileList object 
    // Loop through the FileList 
    for (var i = 0, f; f = files[i]; i++) { 

     var reader = new FileReader(); 
     parser=new DOMParser(); 
     // Closure to capture the file information. 
     reader.onload = (function(theFile) { 
      return function(e) { 
       // Print the contents of the file 
       // var span = document.createElement('span'); 
       xmlDoc=parser.parseFromString(e.target.result,"text/xml"); 
       try{ 
        DistributomeXML_Objects=xmlDoc.documentElement.childNodes; 
       }catch(error){ 
       DistributomeXML_Objects=xmlDoc.childNodes; 
       } 
       //document.getElementById('list').insertBefore(span, null); 
      }; 
     })(f); 

     // Read in the file 
     //reader.readAsDataText(f,UTF-8); 
     reader.readAsText(f); 
    } 
    //xmlDoc.getElementsByTagName("distributome").item(0).appendChild(node); 


    traverseXML(false, null, DistributomeXML_Objects, distributome.nodes, distributome.edges, distributome.references, distributomeNodes, referenceNodes); 
} 

我要檢查,如果xmlDoc中是有效的。如果不使用print語句,這將是一個很好的方法。

+0

你的意思是沒有用' console.log'?爲什麼? –

回答

2

您可以使用控制檯並使用

console.log("my variable content",variable); 

登錄變量的內容,你可以使用Firebug或Chrome或Opera的機控制檯看到它在瀏覽器控制檯...

+0

你在開發中使用什麼? –

+0

我只是使用Chrome瀏覽器 - 你有什麼建議嗎? –

+0

以及鉻控制檯是偉大的,但我建議你使用firebug插件火狐看看它,你可以看到更多的功能,你可以調試你的JavaScript代碼一步一步吧 –