指定由腳本引擎解釋的頁(yè)面中的腳本。
Specifies a script for the page that is interpreted by a script engine.
SCRIPT 塊內的代碼如果不包含在函數內,那么將會(huì )在頁(yè)面載入時(shí)立即執行。要保證腳本不在較低版本的瀏覽器中顯示,應該將 SCRIPT 塊嵌套在 COMMENT 塊內。
FRAMESET 元素后出現的腳本將被忽略。
此元素在 Internet Explorer 3.0 及以上版本的 HTML 中可用,在 Internet Explorer 4.0 及以上版本的腳本中可用。
只要沒(méi)有在 SCRIPT 對象中定義 language 屬性,MSHTML 就會(huì )嘗試使用恰當的腳本引擎。如果選擇了錯誤的腳本引擎,那么通常會(huì )產(chǎn)生錯誤。如果在一個(gè)頁(yè)面中使用了多個(gè) SCRIPT 對象,則可能需要為每個(gè) SCRIPT 對象指定 language 屬性,而且推薦這么做。一個(gè)文檔中 SCRIPT 對象的順序也很重要,特別是為文檔中一個(gè)或多個(gè)元素指定的腳本事件句柄。擴展標記語(yǔ)言(XML)是 SCRIPT 對象的合法內容,但 XML 并不是一種腳本語(yǔ)言。因此,如果 MSHTML 把包含事件句柄函數的 SCRIPT 對象看作了 XML 數據島,將會(huì )發(fā)生錯誤。之所以會(huì )產(chǎn)生這樣的結果,是因為 MSHTML 會(huì )將第一個(gè)有 language 屬性的 SCRIPT 對象作為事件句柄的默認引擎塊。有關(guān)更多信息,請參看示例。
此元素不顯示。
此元素需要關(guān)閉標簽。
Code within the SCRIPT block that is not contained within a function is executed immediately as the page is loaded. To keep scripts from being displayed on down-level browsers, nest the SCRIPT block within a COMMENT block.
Script appearing after a FRAMESET element is ignored.
This element is available in HTML as of Internet Explorer 3.0, and in script as of Internet Explorer 4.0.
Whenever the language attribute is not defined on the SCRIPT object, then MSHTML attempts to select a suitable scripting engine. An error generally occurs if the wrong scripting engine is selected. When more than one SCRIPT object is used on a page, it can be necessary to specify the language attribute for each SCRIPT object, and doing so is always recommended. The order of the SCRIPT objects in a document can also be important, especially if scripting event handlers are assigned to one or more elements in the document. Extensible Markup Language (XML) is legitimate content for the SCRIPT object, but XML is not a scripting language. Therefore, an error can occur if MSHTML selects an XML data island as the SCRIPT object that contains an event handler function. This can happen because MSHTML selects the first SCRIPT object that has the language attribute defined as the default script block for event handlers. For more information, see the examples.
This element is not rendered.
This element requires a closing tag.
The following code snippet provides a scenario where an error occurs.
下面的代碼段提供了發(fā)生錯誤的典型例子。
<html>
<head>
<SCRIPT LANGUAGE="XML" id="mySrc1">
<offerings>
<class><materials>This should render.</materials><time>1.5
hr</time></class>
</offerings>
</SCRIPT>
<SCRIPT LANGUAGE="Javascript">
function returnIslandRootName()
{var islandRoot = document.all["mySrc1"].XMLDocument;
alert(islandRoot.nodeName);
}
</SCRIPT>
</head>
<body>
<button onclick="returnIslandRootName()">Test the XML Data Island</button>
</body>
</html>
由于 XML 數據島是定義了 langauge 屬性的第一個(gè) SCRIPT 對象,MSHTML 會(huì )嘗試將 returnIslandRootName 函數以 XML 裝入,這當然會(huì )導致失敗。要修正這個(gè)例子,只需要更改 SCRIPT 對象的順序,如下所示:
Because the XML data island is the first instance of the SCRIPT object that has the language attribute defined, MSHTML attempts to locate the returnIslandRootName function in the XML and fails. To correct the sample, the order of the SCRIPT objects can changed, as shown by the following:
<html>
<head>
<SCRIPT LANGUAGE="Javascript">
function returnIslandRootName()
{var islandRoot = document.all["mySrc1"].XMLDocument;
alert(islandRoot.nodeName);
}
</SCRIPT>
<SCRIPT LANGUAGE="XML" id="mySrc1">
<offerings>
<class><materials>This should render.</materials><time>1.5
hr</time></class>
</offerings>
</SCRIPT>
</head>
<body>
<button onclick="returnIslandRootName()">Test the XML Data Island</button>
</body>
</html>
聯(lián)系客服