1. js对象
1.1 object对象
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>object对象</title>
</head>
<body>
<script>
var obj = new Object();
console.log(obj , typeof(obj))
obj.name = "孙坚";
obj.age = 18;
obj.weight = "200斤";
obj.eat = function(){
alert("我会吃竹子");
}
console.log(obj.name)
var obj = {
name:"张三",
"age" : 20,
sex : "男性",
drink : function(something){
console.log("我会喝牛栏山",something);
}
}
console.log(obj.sex)
obj.drink("老白干")
console.log(obj["age"])
obj["drink"](1)
var str = "name"
console.log(obj.str , "<==========================>")
console.log(obj.name)
console.log(obj[str])
eval("console.log(333)")
function Person(name,age,sex){
this.name = name;
this.age = age;
this.sex = sex;
this.func = function(){
console.log("我是func");
return this.sex;
}
}
var obj1 = new Person("刘一风",30,"男性");
var obj2 = new Person("张三风",90,"女性");
console.log(obj1.name);
var res = obj1.func();
console.log(res);
console.log(obj2.name)
var res = obj2.func();
console.log(res);
for(var i in obj1){
console.log(i)
}
with(obj1){
console.log(name);
console.log(sex);
console.log(age);
res = func();
console.log(res);
}
console.log("<===================================>")
for(var i in obj1){
with(obj1){
console.log(eval(i))
}
}
</script>
</body>
</html>
1.2 json对象
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>json对象</title>
</head>
<body>
<script>
var data = {
'name':"文东",
age:20,
"sleep":function(){
alert("文东一天睡23小时,还有一个小时上厕所.");
}
}
var res = JSON.stringify(data);
console.log(res , typeof(res));
res = '{"name":"东东","age":30}';
var res2 = JSON.parse(res);
console.log(res2,typeof(res2));
</script>
</body>
</html>
2. js字符串函数
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>字符串对象的相关方法</title>
</head>
<body>
<script>
var string = "to be or not to be";
var res = string.length
var res = string[-1]
console.log(res)
var res = string.trim()
console.log(string)
console.log(res)
var string = "to be or not to be";
var res = string.indexOf("z")
console.log(res)
var res = string.lastIndexOf("zzz")
console.log(res);
var res = string.concat("d:\\","python32\\","day42");
console.log(res);
var string = "11122233e or not to be";
var res = string.slice(1,7);
var res = string.slice(-5,-1);
console.log(res,"<==1==>")
var string = "11122233e or not to be";
var res = string.substr(3,4)
console.log(res,"<==2==>")
var string = "11122233e or not to be";
var res = string.split(" ")
console.log(res,"<==3==>")
var string = "11122233e Or noT tO be";
res = string.toUpperCase();
res = string.toLowerCase();
console.log(res,"<==4==>")
var string = "aaabbb oldaoy ccc"
var res = string.search(/oldboy/)
console.log(res,"<==5==>")
var string = "我的电话是 : 13838384388 你的电话是: 13854381438"
var res = string.match(/\d{11}/);
var res = string.match(/\d{11}/g);
console.log(res)
console.log(res[0])
console.log(res[1])
var string = "to be or not to be";
var res = string.replace("to","two")
console.log(res,"<==6==>")
function myreplace(string,a,b){
while(string.lastIndexOf(a) != -1){
console.log(1)
string = string.replace(a,b);
}
return string;
}
var string = "to be or not to be";
var res = myreplace(string,"to","two")
console.log(res)
var string = "to be or not to be";
var res = string.replace(/to/g,"two");
console.log(res)
</script>
</body>
</html>
3. js数组函数
4. 定时器
5. BOM对象
|