Kami Wangwang perlu menelepon file JS lainnya. Bagaimana cara menghadapinya?
Lihat contoh gambar acak ini. Di halaman sebagai berikut:
<html> <head> <title> nomor acak </iteme> <script type = "text/javaScript"> // secara acak menggambar nama </script> </head> <body> <sorm> <input type = "Tombol" style = 'font-size: 40px' value = "start" onClick = "start ()"> <input type = "KUPLEY" value = "start" onClick = "start ()"> <input type = "KUPLEY" value = "start" Onclick = "start ()"> <input type = "kancing =" kancing "=" soale "font =" staf-s-so 40px = "staf-s-soile" font = "font lyte =" St. "font" OnClick = "stop ();"> </form> <br> <font color = "blue" style = 'font-size: 150px' id = "num"> </font> <br> </body> </html>
Kami dapat memasukkan JS di file lain, seperti A.JS di folder saat ini.
Halaman HTML adalah sebagai berikut:
<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 = "blue" style = 'font-size: 150px' id = "num"> </font> <br> </body> </html>
A.JS
var errorstring = "Harap masukkan bilangan bulat positif."; var arr = ["a", "b", "c", "d"]; function count () {max = arr.length; // max, variabel global variabel.getElementById ("num"). innerHtml = arr [parseInt (max * math.random ())];} function start () {timeid = setInterval ("count ();", 100);} function stop () {clearInterval (timeid);}Itu saja.
Tentu saja, Anda juga dapat meletakkan A.JS di web dan kemudian merujuknya sebagai berikut.
<html> <head> <title> nomor acak </iteme> <script type = "text/javascript" src = "http: // localhost: 8080/test/js/random1.js"> </script> </head> <body> <sorm> <Form> <input type = "button" start = 'pula; "pula; type = "tombol" style = 'font-size: 40px' value = "stop" ontClick = "stop ();"> </form> <br> <font color = "blue" style = 'font-size: 150px' id = "num"> </font> <br> </body> </html>
Di atas adalah metode memperkenalkan (memanggil) file js yang diperkenalkan editor kepada Anda. Saya harap ini akan membantu Anda. Jika Anda memiliki pertanyaan, silakan tinggalkan saya pesan dan editor akan membalas Anda tepat waktu. Terima kasih banyak atas dukungan Anda untuk situs web wulin.com