将json对象的值传到form表单里

loadLocal = function(form, json) {

			$.each(form.serializeArray(), function(index) {
				var name = this['name'];
				for ( var a in json) {
					var key = "";
					var val = "";
					if (name.indexOf('.') != -1) {
						key = name.split('.')[0];
						var getval = name.split('.')[1];
						val = json[a][getval];

					} else {
						key = name;
						val = json[a];
					}
					if ($.trim(key) == $.trim(a)) {
						var eve = $(form).find("[name='" + name + "']");
						if ($(eve).length > 1) {
							for ( var i = 0; i < $(eve).length; i++) {
								//判断单选按钮
								if ($($(eve)[i]).attr("type") == 'radio') {
									if ($($(eve)[i]).val() == val) {
										$($(eve)[i]).attr("checked", true);
									}
								}
							}
						} else {
							$(eve).val(val);
						}
					}
				}
			});
		};
Name:
Email:
Subject:
Message:
Language:
ab

 
  
 
  
 
 

你可能感兴趣的:(js)