Wir müssen andere JS -Dateien anrufen. Wie geht es damit um?
Siehe dieses Beispiel der zufälligen Zeichnung. In einer Seite wie folgt:
<html> <kopf> <titels> Zufällige Nummer </title> <script type = "text/javaScript"> // Zeichnen Sie zufällig den Namen </script> </head> <body> <form> <Eingabe type = "button" style = 'font-size: 40px' value = "start" onclick = "stoppx"> "stoppx". onclick = "stop ();"> </form> <br> <font color = "blau" style = 'font-size: 150px' id = "num"> </font> <br> </body> </html>
Wir können JS in eine andere Datei wie A.JS in den aktuellen Ordner einfügen.
Die HTML -Seite lautet wie folgt:
<html><head><title>random number</title><script type="text/javascript" src="a.js"></script></head><body><form><form><input type="button" style='font-size:40px' value="Start" onclick="start()"><input type="button" style='font-size:40px' value="Stop" onclick = "stop ();"> </form> <br> <font color = "blau" style = 'font-size: 150px' id = "num"> </font> <br> </body> </html>
A.JS
var fehlerstring = "Bitte geben Sie eine positive Ganzzahl ein."; var arr = ["a", "b", "c", "d"]; Funktion count () {max = arr.length; // max, globales variable document.getElementById ("num"). InnerHtml = arr [parseInt (max * math.random ());} function start () {timeId = setInterval ("count ();", 100);Das ist alles.
Natürlich können Sie A.Js auch in das Web setzen und es dann wie folgt verweisen.
<html> <Head> <titels> Zufällige Nummer </title> <script type = "text/javaScript" src = "http: // localhost: 8080/test/js/random1.js"> </script> </head> <body> <form> <form> <input type = "style = 'font size: 40px' Value". type = "button" style = 'font-size: 40px' value = "stop" onclick = "stop ();"> </form> <br> <font color = "blau" style = 'font-size: 150px' id = "num"> </font> <br> </body> </html> </html> </html>
Die obige Methode ist die Methode zur Einführung (Aufrufen) einer JS -Datei, die der Editor Ihnen vorgestellt hat. Ich hoffe, es wird Ihnen hilfreich sein. Wenn Sie Fragen haben, hinterlassen Sie mir bitte eine Nachricht und der Editor wird Ihnen rechtzeitig antworten. Vielen Dank für Ihre Unterstützung für die Wulin.com -Website