简体   繁体   English

脚本不执行

[英]The script doesn't execute

I use node.js so after some operation I use the code : 我使用node.js,因此在进行一些操作后,我将使用代码:

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

to show this html page. 显示此html页面。 The showPlayers.html's code is: showPlayers.html的代码是:

<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. 在脚本中有一个“ console.log ”,当node.js程序将我重定向到此页面时,我仅看到thead的表,并且控制台没有输出。 If I click on the "showPlayers.html" and I run the page is show correctly. 如果我单击“ showPlayers.html”,则我运行的页面正确显示。 Anyone can help me? 有人可以帮助我吗?

Your javascript is working correctly. 您的JavaScript正常运行。 The BAU text does go to the console log - but you have to note where this is running. BAU文本确实进入控制台日志-但您必须注意它的运行位置。 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. 它在浏览器的javascript中,因此转到的控制台日志是浏览器控制台日志,而不是node.js控制台日志。 If you're in FireFox, for example, you would go to Tools/Web Developer/Browser Console to see the output from your javascript. 例如,如果您使用的是FireFox,则可以转到“工具/ Web开发人员/浏览器控制台”查看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: 在我的Mac上,它与html一起显示了以下内容,第一行表明这正确地来自html文件的第18行:
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输出,在右侧看到BAU输出到浏览器控制台。
该图显示了HTML控制台输出

Running same file from node.js, I get this output in Firefox: 从node.js运行相同的文件,我在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? 您确定要在FireFox控制台窗口而不是node.js窗口中显示“ BAU”文本吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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