What are the attributes of the JS script tag:
There are two ways to use the <script> element: embedding When using the script> element to embed JavaScript code, you only need to specify the type attribute for the script>. Then, just put the JavaScript code directly inside the element like this: scripttype="text/javascript"> functionsayHi(){ alert("Hi!"); } /script> The When using For example, a browser will generate an error when loading the following code: scripttype="text/javascript"> functionsayScript(){ alert('/script>'); } /scrìpt> Because according to the rules for parsing embedded code, when the browser encounters the string " For example: What are the attributes of the JSscript> tag: functionsayScript(){ alert("/scr"+"ipt>"); } Writing it in two parts like this will not cause misunderstandings by the browser and thus will not cause errors. If you are including an external For example: scripttype="text/javascript"src="example.js">/script> In this example, the external file For example: scripttype="text/javascript"src="example.js"/> However, you cannot use this syntax in HTML documents. The reason is that this syntax does not conform to the HTML specification and cannot be correctly parsed by some browsers, especially IE. By convention, external JavaScript files have a js extension. This extension is not required, however, as browsers do not check the extension of files containing JavaScript. This makes it possible to dynamically generate JavaScript code using JSP, PHP or other server-side languages. It is important to note that a script> element with a src attribute should not contain additional JavaScript code between the script> and /script> tags. In addition, you can include JavaScript files from external domains via the src attribute of the <script> element. This is what makes the script> element both powerful and controversial. In this respect, the script> element is very similar to the img> element, that is, its src attribute can point to a URL in a domain other than the domain of the current HTML page, for example: scripttype="text/javascript"src="http://www.somewhere.com/afile.js">/script> This way, code located in external domains will be loaded and parsed just as if it were located in the page that loaded it. This allows you to serve JavaScript files from a different domain if necessary. However, you should be careful when accessing JavaScript files on a server that you do not control. If you are unlucky enough to encounter a malicious programmer, they may replace the code in this file at any time. Therefore, if you want to include code from a different domain, either you are the owner of that domain or the owner of that domain is trustworthy. No matter how you include the code, the browser will parse them in the order in which the script> elements appear on the page. In other words, after the code contained in the first script> element is parsed, the code contained in the second script> will be parsed, and then the third and fourth. This is the end of this article about the attributes of the JSscript tag. For more information about the attributes of the JSscript tag, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Three principles of efficient navigation design that web designers must know
>>: SQL uses ROW_NUMBER() OVER function to generate sequence number
Yesterday I wanted to use a:visited to change the...
Let’s not start with the introduction and get str...
Apache Superset is a powerful BI tool that provid...
Table of contents Solution 1: Rebuild Replicas Pr...
webpack loads css files and its configuration Aft...
1. Mirror images disappear in 50 and 93 [root@h50...
This article example shares the specific code of ...
Recently, when I was doing a practice project, I ...
Today I experimented with the network settings un...
Table of contents 1. Introduction 2. RC and RR is...
The vue project built with cli3 is known as a zer...
There is a difference between src and href, and t...
Basic Introduction to Floating In the standard do...
This article uses examples to illustrate the usag...
Table of contents 1. Prepare materials 2. Downloa...