Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从表数据创建数组并当前获取数组中的空字符串_Javascript_Html_Arrays_Razor - Fatal编程技术网

Javascript 从表数据创建数组并当前获取数组中的空字符串

Javascript 从表数据创建数组并当前获取数组中的空字符串,javascript,html,arrays,razor,Javascript,Html,Arrays,Razor,我有一个表,所有者要在其中输入详细信息: <table id="ownerDetailsTable" style="margin-top: 20px; margin-bottom: 20px; width: 100%"> <thead> <tr> <td style="font-weight: bold">

我有一个表,所有者要在其中输入详细信息:

<table id="ownerDetailsTable" style="margin-top: 20px; margin-bottom: 20px; width: 100%">
                    <thead>
                        <tr>
                            <td style="font-weight: bold">HP Point of Contact Name</td>
                            <td style="font-weight: bold">HP Point of Contact Title</td>
                            <td style="font-weight: bold">HP Point of contact email</td>
                        </tr>
                    </thead>
                    <tbody id="tableToModify">
                        <tr id="1">

                            <td>

                                @Html.TextBoxFor(m => m.InterventionOwnerName, new { @class = "form-control element-one", @maxlength = 250, placeholder = "Owner Name", value = "" })
                            </td>
                            <td>

                                @Html.TextBoxFor(m => m.InterverntionOwnerTitle, new { @class = "form-control element-two", @maxlength = 250, placeholder = "Owner Title", value = "" })
                            </td>
                            <td>

                                @Html.TextBoxFor(m => m.InterventionOwnerEmail, new { @class = "form-control element-three", @maxlength = 250, placeholder = "Owner Email", value = "" })
                            </td>

                        </tr>
                    </tbody>
                </table>
                <input id="addRow" , type="button" onclick="createRow(); getOwnerDetails()" value="Add Point of Contact" class="btn btn-primary" />

HP联系人姓名
HP联系人名称
HP联系人电子邮件
@TextBoxFor(m=>m.InterventionOwnerName,新的{@class=“form control element one”,@maxlength=250,placeholder=“Owner Name”,value=”“})
@TextBoxFor(m=>m.interventionownertite,新的{@class=“formcontrolelement-two”,@maxlength=250,placeholder=“Owner-Title”,value=”“})
@Html.TextBoxFor(m=>m.InterventionOwnerEmail,新的{@class=“formcontrolelementthree”,@maxlength=250,placeholder=“Owner Email”,value=”“})
当前,单击会创建一个新的输入行,用户输入的详细信息将进入一个数组:

<script>
        var ownerDetailArray = [];
        function getOwnerDetails() {
            $('table#ownerDetailsTable tr').each(function () {
                var arrayOfThisRow = [];
                var tableData = $(this).find('input');
                if (tableData.length > 0) {
                    tableData.each(function () {
                        arrayOfThisRow.push($(this).text())
                    });
                    ownerDetailArray.push(arrayOfThisRow);
                }
                console.log(ownerDetailArray);
            });
        }

var ownerDetailArray=[];
函数getOwnerDetails(){
$('table#ownerDetailsTable tr')。每个(函数(){
var arrayOfThisRow=[];
var tableData=$(this.find('input');
如果(tableData.length>0){
tableData.each(函数(){
arrayOfThisRow.push($(this.text())
});
ownerDetailArray.push(本排的阵列);
}
控制台日志(所有者详细信息);
});
}

正在创建数组,但数组中的字符串(应为用户输入的信息)为空。我觉得在我试图找到数据并将其推送到阵列中的过程中,似乎存在问题。任何帮助/建议都将不胜感激

如果您试图获取输入值,则将
arrayOfThisRow.push($(this.text())
更改为
arrayOfThisRow.push($(this.val())
我假设您的
@Html.TextBoxFor
创建了
标记

var ownerDetailArray=[];
函数getOwnerDetails(){
$('table#ownerDetailsTable tr')。每个(函数(){
var arrayOfThisRow=[];
var tableData=$(this.find('input');
如果(tableData.length>0){
tableData.each(函数(){
arrayOfThisRow.push($(this.val());
});
ownerDetailArray.push(本排的阵列);
}
控制台日志(所有者详细信息);
});
}

HP联系人姓名
HP联系人名称
HP联系人电子邮件
m、 InterferenceOwnerName,新的{@>class=“表单控制元素一”,@maxlength=250,占位符=“所有者名称”,值=”“})
@TextBoxFor(m=>m.interventionownertite,新的{@class=“formcontrolelement-two”,@maxlength=250,placeholder=“Owner-Title”,value=”“})
@Html.TextBoxFor(m=>m.InterventionOwnerEmail,新的{@class=“formcontrolelementthree”,@maxlength=250,placeholder=“Owner Email”,value=”“})

如果您试图获取输入值,则将
arrayOfThisRow.push($(this.text())
更改为
arrayOfThisRow.push($(this.val())
我假设您的
@Html.TextBoxFor
创建了
标记

var ownerDetailArray=[];
函数getOwnerDetails(){
$('table#ownerDetailsTable tr')。每个(函数(){
var arrayOfThisRow=[];
var tableData=$(this.find('input');
如果(tableData.length>0){
tableData.each(函数(){
arrayOfThisRow.push($(this.val());
});
ownerDetailArray.push(本排的阵列);
}
控制台日志(所有者详细信息);
});
}

HP联系人姓名
HP联系人名称
HP联系人电子邮件
m、 InterferenceOwnerName,新的{@>class=“表单控制元素一”,@maxlength=250,占位符=“所有者名称”,值=”“})
@TextBoxFor(m=>m.interventionownertite,新的{@class=“formcontrolelement-two”,@maxlength=250,placeholder=“Owner-Title”,value=”“})
@Html.TextBoxFor(m=>m.InterventionOwnerEmail,新的{@class=“formcontrolelementthree”,@maxlength=250,placeholder=“Owner Email”,value=”“})