随笔 - 181  文章 - 15  trackbacks - 0
<2009年3月>
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(1)

随笔分类

随笔档案

My Tech blog

搜索

  •  

最新评论

阅读排行榜

评论排行榜

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 阅读(235) 评论(0)  编辑 收藏 引用 所属分类: 我的读书笔记

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理