加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

json2form

发布时间:2020-12-16 19:24:13 所属栏目:百科 来源:网络整理
导读:%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"html xmlns="http://www.w3.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/json2.js" type="text/javascript"></script>
    <script type="text/javascript">
        function test() {
            var json = $("form").form2json();
            $.post("Default3.aspx",json,function (data) {

            },"json");
        }

        $.fn.form2json = function () {
            var o = {};
            var a = this.serializeArray();
            $.each(a,function () {
                if (o[this.name]) {
                    if (!o[this.name].push) {
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });
            return o;
        }
    </script>
</head>
<body>
    <form id="myForm" runat="server">
    <div>
        用户名:<input type="text" id="UserName" name="UserName" /><br />
        部门:<select id="Department" name="Department">
            <option value="">请选择</option>
            <option value="1">财务部</option>
            <option value="2">技术部</option>
        </select><br />
        <input type="button" value="将所有表单元素化为JSON并提交表单" id="" onclick="test()" />
    </div>
    </form>
</body>
</html>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读