jcjssl

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;
};

 

分类:

技术点:

相关文章:

  • 2021-12-09
  • 2021-12-09
  • 2021-10-03
  • 2021-12-21
  • 2021-11-29
猜你喜欢
  • 2021-12-05
  • 2021-12-15
  • 2021-10-03
  • 2021-12-05
  • 2021-12-05
相关资源
相似解决方案