Jquery获取数组中div内的文本框和下拉值 [英] Jquery get text box and dropdown values inside div in array

查看:83
本文介绍了Jquery获取数组中div内的文本框和下拉值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



基本上在jQuery中,我多次克隆一个div,在里面我有3个文本框和一个下拉列表。现在,我希望在数组中的每个div内得到3个文本框和我的一个下拉值,并希望在控制器中传递它。

Ex:



Hello,

Basically in jQuery, I clone a div multiple time and inside it I have 3 textboxes and a dropdown. Now, I want to get 3 text box and my one dropdown value inside every div in array and want to pass that in controller.
Ex:




<div class="col-md-12 m-t-5 NewVehicle">
                                            
                                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
                                                <div class="form-group">
                                                    <label for="VehicleYear">Year/Make</label><span class="text-danger">*</span>
                                                    <div style="display:flex;">
                                                        <input class="form-control m-r-5" id="txtVehicleYear" type="text" />
                                                        <input class="form-control" id="txtVehicleMake" type="text">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="VehicleModel">Model</label><span class="text-danger">*</span>
                                                    <input class="form-control" id="txtVehicleModel" type="text">
                                                </div>
                                                <div class="form-group">
                                                    <label for="VehicleType">Vehicle Type</label><span class="text-danger">*</span>
                                                    @Html.DropDownListFor(Model => Model.lstVehicleType, new SelectList(Model.lstVehicleType, "Value", "Text"), new { @class = "form-control", @id = "ddlNewVehicleType" })
                                                </div>
                                            </div>
                                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
                                            </div>
                                        </div>





我尝试了什么:



我试过jquery但是里面的所有值都是一个数组。

var inputArray = [];

$('#dvNewVehicle')。find(select,text,input)。each(function(){

var cntrlId = $(this).attr('id');

inputArray.push($(#+ cntrlId +)。val()。trim());

});



以上返回value1,value2,value3,value4,value5,value6但我希望它为[{value1,value2,value3},{value4,value5,value6}]。

一个列表中的一个div值。



What I have tried:

I have tried with jquery but all values in inside comes in a single array.
var inputArray = [];
$('#dvNewVehicle').find("select, text, input").each(function () {
var cntrlId = $(this).attr('id');
inputArray.push($("#" + cntrlId + "").val().trim());
});

above returns me value1, value2, value3, value4, value5, value6 but I want it as [{value1, value2, value3},{value4, value5, value6}].
one div values in one list.

推荐答案

('#dvNewVehicle')。find(select,text,input)。each(function (){

var cntrlId =
('#dvNewVehicle').find("select, text, input").each(function () {
var cntrlId =


(this).attr('id');

inputArray.push(
(this).attr('id');
inputArray.push(


(#+ cntrlId +)。val() .trim());

});



以上返回value1,value2,value3,value4,value5,value6但我想要它为[{value1,value2,value3},{value4,value5,value6}]。

一个列表中的一个div值。
("#" + cntrlId + "").val().trim());
});

above returns me value1, value2, value3, value4, value5, value6 but I want it as [{value1, value2, value3},{value4, value5, value6}].
one div values in one list.


这篇关于Jquery获取数组中div内的文本框和下拉值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆