下面小妖就为大家带来一篇基于jQuery的表单填充实例。小妖觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小妖过来看看吧

如下所示:

//表单填充
  , 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]);
       }
      });
     }
    }
   }
  }
原文地址: http://www.cnblogs.com/gaocong/p/7404531.html