javascript-对象的创建(一)
<!DOCTYPE html> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> <html> <script src="<%=request.getContextPath() %>/js/jquery-1.8.0.js" type="text/javascript"></script> <head> <title></title> </head> <body > <div><input type="button" value='测试' id="test_demo" /></div> </body> <script type="text/javascript"> $(function(){ var t1 = function (a,b){ return a+b; } $("#test_demo").on('click',function(){ var user = {}; user.name='张三'; user.age = 18; user.setAge = function(_age){ this.age =_age; }; user.setName = function(_name){ this.name = _name; }; user.add = t1; user.setAge("小李"); user.setName(21); console.info(user); console.info(user.add(2,1)); var userRecord = new Object(); userRecord.user=user; userRecord.pritln = function(){ alert(this.user.name); alert(this.user.age); } userRecord.pritln(); }); }); </script> </html>