zoukankan      html  css  js  c++  java
  • 一个很好介绍js的例子

    function UpdateInit(opt){
    this.init(opt);
    }

    UpdateInit.prototype={
    loadUrl:null,
    loadParam:null,
    beforeLoad:null,
    afterLoad:null,
    beforeInit:null,
    afterInit:null,
    customInit:null,
    init:function(opt){
    this.loadUrl=opt.loadUrl;
    this.loadParam=opt.loadParam;
    this.beforeLoad=opt.afterLoad;
    this.afterLoad=opt.afterLoad;
    this.beforeInit=opt.beforeInit
    this.afterInit=opt.afterInit;
    this.customInit=opt.customInit;
    },

    load:function(){
    if(typeof(this.beforeLoad)=="function"){
    this.beforeLoad(this);
    }
    var param={};
    param.reqUrl=this.loadUrl;
    param.reqData=this.loadParam;
    if(typeof(this.customInit)=="function"){
    ajaxRequest(param,this.customInit,this.loadError,null,this);
    }
    else{
    ajaxRequest(param,this.initData,this.loadError,this,this);
    }
    },
    initData:function(d){
    if(!d){

    return;
    }

    if(typeof(this.afterLoad)=="function"){
    this.afterLoad();
    }
    if(typeof(this.beforeInit)=="function"){
    this.beforeInit(d);
    }
    var itms=$(":input[type!='button']");
    var $divInputer=null;
    var tempVal=null;
    for(var i=0,len=itms.length;i<len;i++){
    tempVal=d[itms[i].name];
    tempVal=tempVal!=null&&tempVal!="null"?tempVal:"";
    if(typeof tempVal =="string"){
    tempVal=tempVal.toString().replace(/(^s*)|(s*$)/g, "");
    }

    //保留几位小数
    var dec=$(itms[i]).attr("decim");
    if(tempVal===0||(dec!=null&&tempVal!=null&&tempVal!=""&&!isNaN(dec)&&!isNaN(tempVal)&&dec>0&&dec<20))
    {
    tempVal=tempVal.toFixed(dec);
    }
    $(itms[i]).val(tempVal);
    $divInputer=$("#for_"+itms[i].name);
    if($divInputer.length>0){
    $divInputer.append(tempVal);
    //$divInputer.append("").focus();
    //$divInputer.html($divInputer.html());
    }

    }
    if(typeof(this.afterInit)=="function"){
    this.afterInit(d);
    }
    },

    loadError:function(){
    if(typeof(this.afterLoad)=="function"){
    this.afterLoad();
    }

    }

    };

  • 相关阅读:
    3089:爬楼梯
    7592:求最大公约数问题
    JVM中内存回收深入分析,各种垃圾收集器
    PKU 1064 Cable master
    【面试&笔试】ASP.NET的相关问题
    1027. Colors in Mars (20) PAT
    DB_WRITER_PROCESSES与LOG_ARCHIVE_MAX_PROCESSES
    fedora下体验gentoo安装
    一个整数数组里面,除了两个数之外,其他的数字都出现了两次,写一个程序找出这两个数
    [置顶] export命令-linux
  • 原文地址:https://www.cnblogs.com/mengziHEHE/p/3331063.html
Copyright © 2011-2022 走看看