Wangwang necesitamos llamar a otros archivos JS. ¿Cómo lidiar con eso?
Vea este ejemplo de dibujo aleatorio. En una página de la siguiente manera:
<html> <fead> <title> número aleatorio </title> <script type = "text/javaScript"> // dibuja aleatoriamente el nombre </script> </head> <body> <form> <form de entrada tipo = "botón" style = 'font-size: 40px' value = "inicio" en ondclick = "start ()"> <input type = "bully" style = 'font-size: 40px' value " onClick = "stop ();"> </form> <br> <font color = "blue" style = 'font-size: 150px' id = "num"> </font> <br> </body> </html>
Podemos poner JS en otro archivo, como A.JS en la carpeta actual.
La página HTML es la siguiente:
<html> <fead> <title> número aleatorio </title> <script type = "text/javaScript" src = "a.js"> </script> </head> <body> <form> <form> <form> type = "button" style = 'font-size: 40px' value = "inicio" en click = "start ()"> <input type = "style" style = 'font-size: 40px' value " onClick = "stop ();"> </form> <br> <font color = "blue" style = 'font-size: 150px' id = "num"> </font> <br> </body> </html>
A.JS
var errorString = "Por favor ingrese un entero positivo."; var arr = ["a", "b", "c", "d"]; function count () {max = arr.length; // max, variable global global document.getElementById ("num"). innerhtml = arr [parseInt (max * math.random ())];} function start () {timeId = setInterval ("count ();", 100);} function stop () {clareinterval (timeId);}Eso es todo.
Por supuesto, también puede poner A.JS en la web y luego hacer referencia a lo siguiente.
<html> <fead> <title> número aleatorio </title> <script type = "text/javaScript" src = "http: // localhost: 8080/test/js/random1.js"> </script> </head> <body> <form> <form> <put type = "button" style = 'font-tisiz type = "Button" style = 'font-size: 40px' value = "stop" onClick = "stop ();"> </form> <br> <font color = "blue" style = 'font-size: 150px' id = "num"> </font> <br> </body> </html>>
Lo anterior es el método para introducir (llamar) un archivo JS que el editor le presentó. Espero que te sea útil. Si tiene alguna pregunta, déjame un mensaje y el editor le responderá a tiempo. Muchas gracias por su apoyo al sitio web de Wulin.com