简体   繁体   中英

The script doesn't execute

I use node.js so after some operation I use the code :

res.sendFile(path.join(__dirname+'\\showPlayers.html'));

to show this html page. The showPlayers.html's code is:

<html>
<body>
<table id="giocatori">
<thead>
    <tr>
        <th>Giocatore</th>
        <th>Ruolo</th>
        <th>Costo</th>
        <th>Squadra</th>
        <th>Operazione</th>
    </tr>
</thead>

</table>

</body>
<script type="text/javascript">
console.log("BAU");
var table = document.getElementById("giocatori");

for( var i=0;i<2; i++){
    var row = table.insertRow(i);
    var cell1 = row.insertCell(0);
    var cell2 = row.insertCell(1);
    var cell3=row.insertCell(2);
    var cell4=row.insertCell(3);
    var cell5=row.insertCell(4);
    cell1.innerHTML = "Mario";
    cell2.innerHTML = "DIF";
    cell3.innerHTML = "10";
    cell4.innerHTML = "Juve";
    cell5.innerHTML = '<form method="post" action="/giocatore"> <input type="submit" name="a" value="Acquista" /> <input type="submit" name="b" value="Cancella" /> </form>';

}
</script>
</html>

In the script there is a " console.log " and when the node.js program redirect me to this page I see only the thead's table and there is no output from console. If I click on the "showPlayers.html" and I run the page is show correctly. Anyone can help me?

Your javascript is working correctly. The BAU text does go to the console log - but you have to note where this is running. It's in javascript in the browser, so the console log that it goes to is the browser console log, not the node.js console log. If you're in FireFox, for example, you would go to Tools/Web Developer/Browser Console to see the output from your javascript. On my Mac, it shows the following with your html, the first line showing that this comes, correctly, from line 18 in the html file:
BAU文本显示在浏览器控制台中

When I execute your script, I see the following in my browser. You;ll see your html output on the left and the BAU output to the browser console on the right.
该图显示了HTML控制台输出

Running same file from node.js, I get this output in Firefox: 运行node.js的图像
Are you sure that you're looking for the "BAU" text to appear in the FireFox console window and NOT the node.js window?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM