Six, JavaScript's call external JavaScript file

An external JavaScript file, no need to write <SCRIPT> tag, myScript.js code is as follows:

Two, index.php code below

Third, the operating results are as follows

Fourth, after clicking

myScript.php follows

function myFunction () { 
   document.getElementById ( "Demo") the innerHTML = "paragraphs have been changed.." ; 
}

index.php as follows

<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<body>
<h2>外部 JavaScript</h2>
<p id="demo">一个段落。</p>

<button type="button" onclick="myFunction()">试一试</button>

<script src="myScript.js"></script>

</body>
</html>

 

Guess you like

Origin www.cnblogs.com/tianpan2019/p/11302489.html