<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>测试</title> <script> "use strict"; var user = {age:15,name:"web",getAge:function(){ alert(this.age) }}; var jorden = { age:30,name:99 } var text = '{ "sites" : [' + '{ "name":"Runoob" , "url":"www.runoob.com" },' + '{ "name":"Google" , "url":"www.google.com" },' + '{ "name":"Taobao" , "url":"www.taobao.com" } ]}'; function checkForm(){ //alert(this);//"use strict"; 严格模式下 返回undefined ;非严格模式返回window 就是该全局对象为 user.getAge(); //输出:15 var age = user.getAge.call(jorden); //返回age=30; user.getAge();//输出:15 //字符串转json解析 var obj = JSON.parse(text); console.log(obj['sites'][0]['name']); //返回sites对象的第一元素Runoob //json对象转换成字符串 var str = {"name":"菜鸟教程", "site":"http://www.runoob.com"}; var str_pretty1 = JSON.stringify(str); console.log(typeof str +" "+ typeof str_pretty1); //输出object string 一个是json对象;一个是字符串 } </script> </head> <body> <form action="#" method="get" name="myform"> <input name="username" value="" type="text"> <input type="submit" value="提交" onclick="checkForm()" > <input type="reset" value="重置"> </form> </body> </html>