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();
    }

    }

    };

  • 相关阅读:
    类,对象和方法
    jmeter对接口测试入参进行MD5加密
    Jmeter配置代理进行录制
    MYSQL——having 和 where的区别
    MySQL
    Python——面试编程题
    mysql——面试题
    Vue——解决跨域请求问题
    Vue——axios网络的基本请求
    ES6 数组map(映射)、reduce(汇总)、filter(过滤器)、forEach(循环迭代)
  • 原文地址:https://www.cnblogs.com/mengziHEHE/p/3331063.html
Copyright © 2011-2022 走看看