JS对象属性(一切事物皆对象):
字符串对象:length(返回长度);indexof(a)(返回第一个字符串出现的位置,没有就是-1);replace(a,b)(替换)返回的修改后的字符串,不会修改原字符串;search(a),返回的也是位置.
var str="hello world!";
document.write(str.length+"<br/>");
document.write(str.indexOf("hello")+"<br/>");
document.write(str.replace("world","JS")+"<br/>");
document.write(str.match("hello")+"<br/>");
document.write(str.search("hello")+"<br/>");
document.write(str);
12
0
hello JS!
hello
0
hello world!
创建JS对象:
var person=new Object();
person.firstname="Bill";
person.lastname="Gates";
person.age=56;
访问对象的属性就是 objectName.propertyName
JS函数语法:
function functionName(){
执行的代码;
}
和后台一样,参数之间用逗号隔开;也可以和后台一样设置return语句
JS同样存在局部变量和全局变量,变量的生存期也和后台一样,JS的生命期从被声明开始,局部变量在函数结束被删除,全局变量则是页面关闭时被删除。