zoukankan      html  css  js  c++  java
  • form

    form 表单 清除

     $('#commentForm')[0].reset();

    form 表单 加载数据 JSON数组

    function loadData(jsonStr) {
                        var obj = eval("(" + jsonStr + ")");
                        var key, value, tagName, type, arr;
                        for (x in obj) {
                            key = x;
                            value = obj[x];
    
                            $("[name='" + key + "'],[name='" + key + "[]']").each(function () {
                                tagName = $(this)[0].tagName;
                                type = $(this).attr('type');
                                if (tagName == 'INPUT') {
                                    if (type == 'radio') {
                                        $(this).attr('checked', $(this).val() == value);
                                    } else if (type == 'checkbox') {
                                        arr = value.split(',');
                                        for (var i = 0; i < arr.length; i++) {
                                            if ($(this).val() == arr[i]) {
                                                $(this).attr('checked', true);
                                                break;
                                            }
                                        }
                                    } else {
                                        $(this).val(value);
                                    }
                                } else if (tagName == 'SELECT' || tagName == 'TEXTAREA') {
                                    $(this).val(value);
                                }
    
                            });
                        }
                    }

    form 表单 转JSON

     var formdata = $("#commentForm").serialize();
  • 相关阅读:
    Python进阶08 生成器
    Python进阶07 迭代
    Python进阶06 列表推导
    Python进阶05 函数property
    Python基础14 集合
    支付宝支付和微信消息推送
    Redis
    django之contenttype
    数据分析系列
    IPython
  • 原文地址:https://www.cnblogs.com/CoreXin/p/4729372.html
Copyright © 2011-2022 走看看