JavaScript外部文件到HTML



我试图将外部文件放在HTML上,但它不起作用。某些文件夹中的文件。

请帮助我,我尝试过。

<script>alert("hi");</script>

<!DOCTYPE html>
    <html>
    <head>
    <script src="/java.js" type="text/javascript"></script>
    </head>
    </html>

这是在同一文件夹中的.html和.js文件的工作解决方案

// scripts.js 
alert('hello');
<!-- index.html -->
<!DOCTYPE html>
<html>
    <head>
        <script src="scripts.js" type="text/javascript"></script>
    </head>
</html>

最新更新