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>”);
相关文档:
打开一个 js 文件,编辑完成保存时,突然提醒下面的错误:
Save could not be completed.
Reason:
Some characters cannot be mapped using “ISO-8859-1″ character encoding. Either change the encoding or remove the characters which are not supported by the “ISO-8859-1″ character ......
function setEnd(field) {
if (field.createTextRange) {
var r = field.createTextRange();
r.moveS ......
一概述
在Java语言中,我们可以定义自己的类,并根据这些类创建对象来使用,在Javascript中,我们也可以定义自己的类,例如定义User类、Hashtable类等等。
目前在Javascript中,已经存在一些标准的类,例如Date、Array、RegExp、String、Math、Number等等,这为我们编程提供了许多方便。但对于复杂的客户端程序而言,这些 ......
1.认识数组
数组就是某类数据的集合,数据类型可以是整型、字符串、甚至是对象
Javascript不支持多维数组,但是因为数组里面可以包含对象(数组也是一个对象),所以数组可以通过相互嵌套实现类似多维数组的功能
1.1 定义数组
声明有10个元素的数组
var a = new Array(10);
此时为a已经开辟了内存空间,包含10个元素 ......
我想使用过ajax的都常见这样的代码:
<a href="javascript:doTest2();void(0);">here</a>
但这儿的void(0)究竟是何含义呢?
Javascript中void是一个操作符,该操作符指定要计算一个表达式但是不返回值。
void 操作符用法格式如下:
1. javascript:void (expression)
2. javascript:void expression
expr ......