日期:2014-05-16  浏览次数:20458 次

Javascript 方法大全

方法大全" href="http://www.itpig.cn/?p=41" rel=bookmark>Javascrīpt 方法大全

1 创建脚本块

1: <scrīpt language=”Javascrīpt”>
S z g%` L02: Javascrīpt code goes here
^ \ ~ [8n%x9p n P03: </scrīpt>

2 隐藏脚本代码

1: <scrīpt language=”Javascrīpt”>
&C D8O G p/T G02: <!–PHPChina 开源社区门户4j w q s0G d
3: document.write(“Hello”);PHPChina 开源社区门户2} G(S Z6\ Y R4b f3y g#l
4: // –>PHPChina 开源社区门户 M3x [ ]/f O ?"y9n
5: </scrīpt>PHPChina 开源社区门户 r g0G c F t
在不支持Javascrīpt的浏览器中将不执行相关代码

3 浏览器不支持的时候显示

1: <noscrīpt>PHPChina 开源社区门户 s Y!K:Y*S
2: Hello to the non-Javascrīpt browser.
4M/q K#^ T03: </noscrīpt>

4 链接外部脚本文件

1: <scrīpt language=”Javascrīpt” src=”/”filename.js” mce_src=”/”filename.js””></scrīpt>PHPChina 开源社区门户 E z-S j o!p
5 注释脚本

1: // This is a comment
X5d"G#S T+\ } v02: document.write(“Hello”); // This is a commentPHPChina 开源社区门户#b {;Q n){ w)[ } @7Y5I
3: /*PHPChina 开源社区门户+C4[0z:~ z ~5G |'c/C
4: All of this
F)u ~ m;e [ C6N05: is a comment
5y G k {7~ N!Y q%U06: */

6 输出到浏览器

1: document.write(“<strong>Hello</strong>”);

7 定义变量

1: var myVariable = “some value”;

8 字符串相加

1: var myString = “String1” + “String2”;

9 字符串搜索

1: <scrīpt language=”Javascrīpt”>PHPChina 开源社区门户"R `8u&N n'n&X
2: <!–PHPChina 开源社区门户9s:O4E T6i k ~
3: var myVariable = “Hello there”;
+^-H#S&q f C9t e%_6i04: var therePlace = myVariable.search(“there”);PHPChina 开源社区门户 ]2f v-l O W c E
5: document.write(therePlace);PHPChina 开源社区门户2u ` y)G*] S3U V(K J2q k k
6: // –>PHPChina 开源社区门户:[ S Y'J }7j a0p9N l _8z
7: </scrīpt>

10 字符串替换

1: thisVar.replace(“Monday”,”Friday”);

11 格式化字串1: <scrīpt language=”Javascrīpt”>PHPChina 开源社区门户2[7Z0P8A c"k
2: <!–PHPChina 开源社区门户!P S"m6C M5~ @.],`
3: var myVariable = “Hello there”;PHPChina 开源社区门户 V P O R n a
4: document.write(myVariable.big() + “<br>”);PHPChina 开源社区门户5a p4B j B(h _,E M g v A
5: document.write(myVariable.blink() + “<br>”);PHPChina 开源社区门户 I ^!l Y c O%v-W
6: document.write(myVariable.bold() + “<br>”);
h N.R-V K#~07: document.write(myVariable.fixed() + “<br>”);
3t G i k F/g X O08: document.write(myVariable.fontcolor(“red”) + “<br>”);
@6] |"S o }*r.o q09: document.write(myVariable.fontsize(“18pt”) + “<br>”);PHPChina 开源社区门户 z _ U!C O o k \;m4`
10: document.write(myVariable.italics() + “<br>”);PHPChina 开源社区门户/^ n&p2}#\ \ Z2G4B9` a
11: document.write(myVariable.small() + “<br>”);
O q.F/|/g5p0L t;J012: document.write(myVariable.strike() + “<br