基于jq的表单填充

 //表单填充
         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]);
                            }
                        });
                    }
                }
            }
        }
posted @ 2017-08-21 18:05  C9  阅读(234)  评论(0编辑  收藏  举报