zoukankan      html  css  js  c++  java
  • js for form

     //表单填充
        表单填充
            , formDataLoad: function (domId, obj) {
                for (var property in obj) {
                    if (obj.hasOwnProperty(property) == true) {
                        if ($("#" + domId + " [name='" + property + "']").size() > 0) {
                            $("#" + domId + " [name='" + property + "']").each(function () {
                                var dom = this;
                                if ($(dom).attr("type") == "radio") {
                                    $(dom).filter("[value='" + obj[property] + "']").attr("checked", true);
                                }
                                if ($(dom).attr("type") == "checkbox") {
                                    obj[property] == true ? $(dom).attr("checked", "checked") : $(dom).attr("checked", "checked").removeAttr("checked");
                                }
                                if ($(dom).attr("type") == "text" || $(dom).prop("tagName") == "SELECT" || $(dom).attr("type") == "hidden" || $(dom).attr("type") == "textarea") {
                                    $(dom).val(obj[property]);
                                }
                                if ($(dom).prop("tagName") == "TEXTAREA") {
                                    $(dom).val(obj[property]);
                                }
                            });
                        }
                    }
                }
            }
     // 绑定单个下拉框方法
        , bindSelectSingle: function (domId, data, defaultVal) {
            /// <summary>
            /// 绑定下拉框方法
            /// </summary>
            /// <param name="domId" type="type">dom的ID</param>
            /// <param name="data" type="type">json数据</param>
            var selectDom$ = $("#" + domId);
            selectDom$.find("option").remove();
            $(data).each(function () {
                selectDom$.append("<option value='" + this.Key + "'>" + this.Value + "</option>");
            });
            if (defaultVal != undefined) {
                selectDom$.val(defaultVal);
            }
        }
     //取url参数
        getUrlVars: function () {
            var vars = {};
            var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
                function (m, key, value) {
                    vars[key] = value;
                   
                }
            );
            return vars;
        }
     , getValueBydataPropAndKey: function (dataProp, key) {
                /// <summary>
                /// 通过数据源属性和下拉框Key得到Value
                /// </summary>
                /// <param name="dataProp" type="string">数据源属性</param>
                /// <param name="key" type="string">下拉框Key</param>
                var json = window.cacheSelectData
                    , arr = JSON.parse(json[dataProp])
                    , value = "";
                $(arr).each(function () {
                    if (this.Key == key) {
                        value = this.Value;
                        return;
                    }
                });
                return value;
            }
     //脏值处理
            , dirtyValueHandle: function (val) {
                if (val == null || val == undefined) {
                    return "";
                } else {
                    return val;
                }
            }
      //url参数转对象,如?name=1&age=20转换后为{name:1,age:20}
            , parseQuery: function (query) {
                var reg = /([^=&s]+)[=s]*([^&s]*)/g;
                var obj = {};
                while (reg.exec(query)) {
                    obj[RegExp.$1] = RegExp.$2;
                }
                return obj;
            }
  • 相关阅读:
    C# 了解当前使用的语言版本
    Swagger api 接口管理 使用总结
    Git 常见错误操作
    NestJs 详解
    推荐一个NodeJS 框架 AdonisJS
    Lavavel8.x
    @typegoose/typegoose. 使用技巧
    Typeorm
    Cocos2Dx(4)——动画
    Java程序员的C#学习笔记(1) C#和.NET Framework概览
  • 原文地址:https://www.cnblogs.com/gaocong/p/7251259.html
Copyright © 2011-2022 走看看