私たちは他のJSファイルを呼び出す必要があります。それに対処する方法は?
ランダムな図面のこの例を参照してください。次のようなページで:
<html> <head> <title>ランダム数</title> <script type = "text/javascript"> //名前をランダムに描画</script> </head> <body> <form> <入力タイプ= "ボタン" style = 'font-size:' font-size: 'font-size:' value = "start" onclick = "start =" button = "fontsize:" font-size: "font-size 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> <スクリプトタイプ= "text/javascript" src = "a.js"> </script> </head> <body> <form> <form> <input type = "button" style = 'font-size:40px' value = "start" onclick = " 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; // gax、global variable document.getElementByid( "num")。innerhtml = arr [parseint(max * math.random());} function start(){timeId = setInterval( "count();"、100);} function stop(){clearinterval(timeid);};}それだけです。
もちろん、A.JSをWebに配置してから、次のように参照することもできます。
<html> <head> <title>ランダム数</title> <スクリプトタイプ= "text/javascript" src = "http:// localhost:8080/test/js/random1.js"> </scrip> </head> <body> <body> <form> <form> <input type = "button"スタイル= 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>
上記は、編集者が紹介したJSファイルを導入(呼び出す)方法です。それがあなたに役立つことを願っています。ご質問がある場合は、メッセージを残してください。編集者は時間内に返信します。 wulin.comのウェブサイトへのご支援ありがとうございます