We Wangwang need to call other js files. How to deal with it?
See this example of random drawing. In a page as follows:
<html><head><title>random number</title><script type="text/javascript">//randomly draw the name</script></head><body><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>
We can put js in another file, such as a.js in the current folder.
The html page is as follows:
<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 = "Please input a positive integer.";var arr = ["A", "B", "C", "D"];function count() {max = arr.length; //max, global variable document.getElementById("num").innerHTML = arr[parseInt(max * Math.random())];}function start(){timeId = setInterval("count();", 100);}function stop() {clearInterval(timeId);}That's all.
Of course, you can also put a.js on the web and then reference it as follows.
<html><head><title>random number</title><script type="text/javascript" src="http://localhost:8080/test/js/random1.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>
The above is the method of introducing (calling) a JS file that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for Wulin.com website