Home > Web Front-end > JS Tutorial > body text

Why Can\'t Inline JavaScript Be Included in External Script Tags?

Susan Sarandon
Release: 2024-10-24 01:15:29
Original
895 people have browsed it

Why Can't Inline JavaScript Be Included in External Script Tags?

Why Can't You Execute JavaScript in External Script Tags?

When using tags, external JavaScript files are loaded and executed. However, attempting to include JavaScript code within such tags, like:

<script src="myFile.js">
    alert( "This is a test" );
</script>
Copy after login

will fail without errors. This is because a script element can only load one script at a time, either from a URL or inline. Including both results in the inline script being ignored.

To execute JavaScript within a page, you need to create multiple

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!