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
Table of contents Preface 1. Environment Configur...
I have used the vi editor for several years, but ...
1. Background As the project's business conti...
Table of contents 01 CMD 02 ENTRYPOINT 03 WORKDIR...
Click here to return to the 123WORDPRESS.COM HTML ...
cause The way to import external files into a min...
Table of Contents Introduction Synchronous Asynch...
Table of contents 1. Relationship between parent ...
MySQL database crashes after entering password an...
A problem occurred when configuring a cluster. Or...
Introduction to HTML HyperText Markup Language: H...
When processing batch updates of certain data, if...
First, open the virtual machine Open xshell5 to c...
Using Javascript to implement countdown to close ...
In the /etc/my.conf file, add the following line ...