JavaScript方法和技巧大全
JavaScript方法和技巧大全 基础知识
1 创建脚本块 <script language=”JavaScript”> JavaScript code goes here </script>
2 隐藏脚本代码 <script language=”JavaScript”><!-- document.write(“Hello”); --> </script>
在不支持JavaScript的浏览器中将不执行相关代码
3 浏览器不支持的时候显示 <noscript> Hello to the non-JavaScript browser.</noscript>
4 链接外部脚本文件<script language=”JavaScript” src="/”filename.js"”></script>
5 注释脚本 // This is a comment
document.write(“Hello”); // This is a comment
/* All of this is a comment */
6 输出到浏览器 document.write(“<strong>Hello</strong>”);
7 定义变量 var myVariable = “some value”;
8 字符串相加 var myString = “String1” + “String2”;
9 字符串搜索 <script language=”JavaScript”><!-- var myVariable = “Hello there”;
var therePlace = myVariable.search(“there”); document.write(therePlace);// --> </script>
10 字符串替换 thisVar.replace(“Monday”,”Friday”);
11 格式化字串 <script language=”JavaScript”><!—
var myVariable = “Hello there”; document.write(myVariable.big() + “<br>”);
document.write(myVariable.blink() + “<br>”); document.write(myVariable.bold() + “<br>”);
document.write(myVariable.fixed() + “<br>”);document.write(myVariable.fontcolor(“red”) + “<br>”);
document.write(myVariable.fontsize(“18pt”) + “<br>”);document.write(myVariable.italics() + “<br>”);
document.write(myVariable.small() + “<br>”);document.write(myVariable.strike() + “<br>”);
相关文档:
尽管那需要用长串的、沉闷的不同分支代码来应付不同浏览器的日子已经过去,偶尔还是有必要做一些简单的区分和目标检测来确保某块代码能在用户的机器上正常运行。在这篇文章中,作者介绍了7个在IE和firefox中不同的JavaScript句法。
1. CSS "float" 值
访问一个给定CSS 值的最基本句法 ......
区分XHTML与HTML的标志:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
前者是XHTML,后者是HTML
浏览器的高和宽:
XHTML:
document.document ......
1.日期对象的构造
1.1当前日期
var now = new Date();
1.2特定日期
var someDate = new Date(yyyy,mm,dd);
注:月应该是从0开始计数的.
2. 日期函数的使用可以参照下面的链接. http://www.w3schoo ......