- var user = {
- userInfo: {
- userName: null,
- password: null,
- birthday: null,
- sex: null,
- age: Nal,
- },
- other: {
- hobby: null,
- hometown: false
- },
- //初始化
- initEvent: function(){
- //可以在这里调用自己的一些方法
- user.birth();
- },
- //出生时期
- birth: function(){
- user.userInfo.userName = "安普尚";
- user.userInfo.password = "123456";
- user.userInfo.birthday = "1992-09-07";
- var ageMessage = user.userInfo.age = 1;
- user.userInfo.sex = "男";
- user.other.hobby = "哭";
- user.other.hometown = false;
- user.hometown(ageMessage);
- },
- //上学
- shangxiaoxue: function(){
- //这里对那些属性进行赋值和自己的一些实际 ,链接数据库进行操作,
- $.post("上学了.action", null, function(){
- //这里发送请求
- });
- },
- shangzhongxue: function(){
- //这里对那些属性进行赋值和自己的一些实际 ,链接数据库进行操作,
- $.post("上学了.action", null, function(){
- //这里发送请求
- });
- },
- shanggaozhong: function(){
- //这里对那些属性进行赋值和自己的一些实际 ,链接数据库进行操作,
- $.post("上学了.action", null, function(){
- //这里发送请求
- });
- },
- //结婚
- hometown: function(ageMessage){
- if (ageMessage > 3 && ageMessage < 6) {
- user.shangxiaoxue();//开始上学了,大哭一场
- }
- if (ageMessage > 14 && ageMessage < 17) {
- user.shangzhongxue();//上中学了,开心
- }
- if (ageMessage > 17 && ageMessage < 20) {
- user.shanggaozhong();//上高中了,想谈恋爱
- }
- if (ageMessage > 20 && ageMessage < 100) {
- user.struggle();//开始奋斗
- }
- else {
- user.die();//不奋斗就在这个阶段死亡
- }
- },
- //奋斗
- struggle: function(){
- user.other.hobby = "开始学习Java";
- },
- //死亡
- die: function(){
- }
- };
- $().ready(function(){
- user.initEvent();
- });
- //该片段来自于http://www.codesnippet.cn/detail/231020136589.html
来源: http://www.codesnippet.cn/detail/231020136589.html