zoukankan      html  css  js  c++  java
  • js获得Form表单内的值

    js获得Form表单内的值

    1.返回的是一个数组

    function getFormData(eId) {
        var inData = new Array();
        $("#" + eId).find("input").each(function () {
            if ($(this).attr("real-value") != null) {
                inData.push({"name": $(this).attr("name"), "value": $(this).attr("real-value").trim()});
            } else {
                inData.push({"name": $(this).attr("name"), "value": $(this).val().trim()});
            }
        });
        $("#" + eId).find("select").each(function () {
            inData.push({"name": $(this).attr("name"), "value": $(this).val().trim()});
        });
        $("#" + eId).find("textarea").each(function () {
            inData.push({"name": $(this).attr("name"), "value": $(this).val().trim()});
        });
        return inData;
    }

    2.返回的是一个对象

    function getFormData(eId) {
        var inData={};
        $("#" + eId).find("input").each(function() {
            if ($(this).attr("real-value") != null) {
                inData[$(this).attr("name")] = $(this).attr("real-value").trim();
            } else {
                inData[$(this).attr("name")] = $(this).val().trim();
            }
        });
    
        $("#" + eId).find("select").each(function() {
            inData[$(this).attr("name")] = $(this).val();
        });
        $("#" + eId).find("textarea").each(function() {
            inData[$(this).attr("name")] = $(this).val().trim();
        });
        return inData;
    };
  • 相关阅读:
    用Python学分析
    用Python学分析
    描述性统计指标
    用Python学分析
    Python练习:哥德巴赫猜想
    用Python学分析
    用Python学分析:集中与分散
    用Python学分析
    Ubuntu安装中文输入法
    Kali Linux ettercap的使用
  • 原文地址:https://www.cnblogs.com/jcjssl/p/9580265.html
Copyright © 2011-2022 走看看