简体   繁体   English

本地文件夹中的console.log问题

[英]console.log issue in a local folder

I just wonder what I am doing with console.log is wrong or not. 我只是想知道我对console.log所做的事情是对还是错。

I have simple two files as below: index.html index.js 我有两个简单的文件,如下所示:index.html index.js

and when opening the index.html in chrome(c:\\temp\\index.html), it does not output console.log message in console tab as below. 并且在chrome(c:\\ temp \\ index.html)中打开index.html时,它不会在控制台选项卡中输出console.log消息,如下所示。 在此处输入图片说明 So am I missing something? 那我想念什么吗?

As you can see, if you run it below code, it shows console.log properly. 如您所见,如果在代码下面运行它,它将正确显示console.log。

 function doSomething() { console.log("Work!"); } doSomething(); 
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div>Hi</div> <script scr='index.js'> </script> </body> </html> 

Looks like you have a typo: 看起来您有错别字:

<script scr='index.js'>

should be 应该

<script src='index.js'>

 function doSomething() { console.log("Work!"); } doSomething(); 
 <div>Hi</div> <script src='index.js'> </script> 

You have to change scr to src in that way it will works. 您必须以这种方式将scr更改为src。

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

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