1、
Html標簽如果環繞javascript代碼,則會作用于它的輸出
如:
<html>
<head>
<script
type="text/javascript">
function sayhello()
{
document.write("hello");
}
</script>
</head>
<body>
<font
size="100">
<script
language="javascript">
sayhello();
</script>
</font>
</body>
</html>
2、
<script language=”javascript”></script>不是W3C標準
W3C標準是:
<script type=”text/javascript”></script>
但是有些瀏覽器不支持type方式聲明javascript腳本,所以你最好兩個都用,就如下面:
<script language=”javascript” type=”text/javascript”></script>
3、
有些瀏覽器在執行腳本的過程中產生輸出,但有些不能
<body>
<h1>Ready start</h1>
<script type="text/javascript">
alert("First
Script Ran");
</script>
<h2>Running...</h2>
<script
type="text/javascript">
alert("Second Script Ran");
</script>
<h2>Keep running</h2>
<script type="text/javascript">
alert("Third Script Ran");
</script>
<h1>Stop!</h1>
</body>
4、
大多數瀏覽器喜歡把它們不支持的標簽中的內容直接顯示出來,如果你碰到一個瀏覽器恰好不支持javascript,你應該:
<script type="text/javascript">
<!--
put your
JavaScript here
//-->
</script>
但是如果你所寫的是嚴格的XHTML,注釋標記就不大合適了,你最好:
<script type="text/javascript">
<![CDATA[
..script here ..
]]>
</script>
5、
如果瀏覽器不支持javascript或者javascript被關閉了,最好寫一段noscript,就像這樣:
<noscript>
<em>Either your browser does not support JavaScript or it
is currently disabled.</em>
</noscript>
一個很有意思的用法就是,如果瀏覽器不支持javascript,就讓他們跳轉到一個錯誤頁面,如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>noscript Redirect Demo</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<!-- warning example does not validate -->
<noscript>
<meta http-equiv="Refresh" content="0;URL=/errors/noscript.html" />
</noscript>
</head>
<body>
<script type="text/javascript">
<!--
document.write("Congratulations! If you see this you have JavaScript.");
//-->
</script>
<noscript>
<h2>Error: JavaScript required</h2>
<p>Read how to <a href="/errors/noscript.html">rectify this problem</a>.</p>
</noscript>
</body>
</html>
6、
事件響應方面,html是不區分大小寫的,onclick,OnClick,onCliCk效果相同,但是在XHTML中,只接受小寫。
大多數瀏覽器支持在地址欄中輸入如javascript: alert('hello')的代碼來運行javascript。當然,也可以以超鏈接的形式:<a href="javascript: alert('hello I am a pseudo-URL script');">Click to invoke</a>
posted on 2008-04-23 11:17
littlegai 閱讀(251)
評論(0) 編輯 收藏 引用 所屬分類:
我的讀書筆記