In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge about "what are the script tag attributes of JS". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
What are the attributes of JS script tags:
Charset: Optional. Represents the character set of the code specified by the src attribute. This property is rarely used because most browsers ignore its value.
defer: optional. Indicates that script execution can be delayed until the document is fully parsed and displayed.
Language: Abandoned. Originally used to indicate the scripting language in which code was written (such as JavaScript, JavaScript 1.2, or VBScript). Most browsers ignore this property, so there is no need to use it again.
src: Optional. Represents an external file that contains code to execute.
Type: Required. Think of it as a surrogate attribute for language, denoting the content type (also known as MIME type) of the scripting language in which the code was written. Although text/javascript and text/ecmascript are no longer recommended, people still use text/javascript. In fact, the MIME type used by the server when transmitting JavaScript files is usually application/x-javascript, but setting this value in type may cause scripts to be ignored. In addition, the following values are available in non-IE browsers: application/javascript and application/ecmascript. For convention and maximum browser compatibility, the type attribute is still text/javascript.
There are two ways to use script> elements: embedding JavaScript code directly in the page and including external JavaScript files.
When embedding JavaScript code using the script> element, you only need to specify the type attribute for script>. Then, place JavaScript code directly inside the element like this:
scripttype="text/javascript"> functionsayHi(){ alert("Hi! "); } /script>
JavaScript code contained within script> elements is interpreted from top to bottom. In the previous example, the interpreter interprets the definition of a function and saves it in its environment. Until the interpreter evaluates all the code inside the script> element, the rest of the page is not loaded or displayed by the browser.
When using script> to embed JavaScript code, remember not to place the "/script>" string anywhere in your code.
For example, the browser generates an error when loading the code shown below:
scripttype="text/javascript"> functionsayScript(){ alert('/script>'); } /scrìpt>
Because according to the rules for parsing embedded code, when the browser encounters the string "/script>," it assumes that it is the closing/script> tag. This problem can be solved by splitting the string into two parts,
For example:
JSscript> What are the attributes of tags:
functionsayScript(){ alert("/scr"+"ipt>"); }
Writing in two parts like this won't cause misunderstandings in browsers and therefore won't lead to errors.
The src attribute is required if you want to include an external JavaScript file via the script> element. The value of this property is a link to an external JavaScript file,
For example:
scripttype="text/javascript"src="example.js">/script>
In this example, the external file example.js will be loaded into the current page. The external file only needs to contain the JavaScript code normally placed between script> at the beginning and/script> at the end. As with parsing embedded JavaScript code, page processing is temporarily halted while parsing an external JavaScript file (including downloading the file). If it's in an XHTML document, you can omit the/script> tag that ends in the previous example code,
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 it does not get correct parsing by some browsers, especially IE.
By convention, external JavaScript files have the js extension. This extension is not required, however, because browsers do not check extensions for files containing JavaScript. This makes it possible to dynamically generate JavaScript code using JSP, PHP, or other server-side languages.
Note that script> elements with src attributes should not contain extra JavaScript code between script> and/script> tags.
Additionally, JavaScript files from external domains can be included via the src attribute of the script> element. This makes script> elements doubly powerful and controversial. script> is very similar to img> in that its src attribute can be a URL pointing to a domain outside the domain of the current HTML page, for example:
scripttype="text/javascript"src="http://www.somewhere.com/afile.js">/script>
In this way, code located in the outer domain is loaded and parsed as if it were located in the page from which it was loaded. This allows JavaScript files to be served through different domains when necessary. Be careful, however, when accessing JavaScript files on servers over which you have no control. If you are unlucky enough to encounter malicious programmers, they can replace the code in the file at any time. So if you want to include code from different domains, either you are the owner of that domain or the owner of that domain is trustworthy.
Regardless of how code is included, the browser parses script> elements in the order they 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> element is parsed, and then the third and fourth elements.
"JS script tag attributes what" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.