1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > js获取form表单数据和form表单赋值

js获取form表单数据和form表单赋值

时间:2024-03-15 09:29:15

相关推荐

js获取form表单数据和form表单赋值

$.fn.extend({

// 调用方式:$("xxxxx").getform();

getform: function () { var obj = {};var array = $(this).serializeArray();$.each(array, function () {obj[this.name] = this.value;});return obj;}, // 调用方式: $("xxx").setform(json);setform: function (jsonValue) {var obj = this;$.each(jsonValue, function (name, ival) {var $input = obj.find("input:[name=" + name + "]");if ($input.attr("type") == "radio" || $input.attr("type") == "checkbox") {$input.each(function () {if (Object.prototype.toString.apply(ival) == '[object Array]') { // 是复选框,并且是数组 for (var i = 0; i < ival.length; i++) {if ($(this).val() == ival[i])$(this).attr("checked", "checked");}} else {if ($(this).val() == ival)$(this).attr("checked", "checked");}});} else if ($input.attr("type") == "textarea") { // 多行文本框 obj.find("[name=" + name + "]").html(ival);} else {obj.find("[name=" + name + "]").val(ival);}});}

});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。