Wangwang은 다른 JS 파일을 호출해야합니다. 그것을 다루는 방법?
임의의 드로잉 의이 예를 참조하십시오. 다음과 같이 페이지에서 :
<html> <head> <title> 랜덤 번호 </title> <script type = "text/javaScript"> // 이름을 무작위로 그려 </script> </script> </head> <body> <form> <form> <form> <form> <form> <form> <form> <form> <body> <body> <button "style = 'font sife : 40px'value ="start () ""value = "style = 40px ' onclick = "stop ();"> </form> <br> <font color = "blue"style = 'font-size : 150px'id = "num"> </font> <br> </body> </html>
현재 폴더의 A.JS와 같은 다른 파일에 JS를 넣을 수 있습니다.
HTML 페이지는 다음과 같습니다.
<html> <head> <title> 랜덤 번호 </title> <script type = "text/javaScript"src = "a.js"> </script> </head> <body> <form> <form> <입력 유형 = "button"Style = 'font-size : 40px'value = "start"onclick = "start ()"style = "skize" value = "stop"onclick = "stop ();"> </form> <br> <font color = "blue"style = 'font-size : 150px'id = "num"> </font> <br> </body> </html>
A.JS
var errorstring = "양의 정수를 입력하십시오."; var arr = [ "a", "b", "c", "d"]; function count () {max = arr.length; // max, 글로벌 변수 문서 ( "num"). innerhtml = arr [parseint (max * math.random ());} function start () {timeid = setinterval ( "count ();", ", 100);} 함수 stop () {clearinterval (timeid);}그게 다야.
물론 A.JS를 웹에 넣은 다음 다음과 같이 참조 할 수도 있습니다.
<html> <head> <title> 랜덤 번호 </title> <script type = "text/javaScript"src = "http : // localhost : 8080/test/js/random1.js"> </script> </head> <body> <form> <form> <입력 형 " 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> <bod> </html>
위는 편집자가 소개 한 JS 파일을 (호출) 소개하는 방법입니다. 나는 그것이 당신에게 도움이되기를 바랍니다. 궁금한 점이 있으면 메시지를 남겨 주시면 편집자가 제 시간에 답장을 드리겠습니다. wulin.com 웹 사이트에 대한 귀하의 지원에 감사드립니다.