Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.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 jQuery-在表中循环时在dropdownlist中获取所选值_Javascript_Jquery_Html.dropdownlistfor - Fatal编程技术网

Javascript jQuery-在表中循环时在dropdownlist中获取所选值

Javascript jQuery-在表中循环时在dropdownlist中获取所选值,javascript,jquery,html.dropdownlistfor,Javascript,Jquery,Html.dropdownlistfor,我编写了这个javascript来获取一个表的Id,然后首先循环通过tr,然后循环通过td。我不知道写什么逻辑来获取td中下拉列表的选定值。并非所有tds都有下拉列表 这是我的javascript function submitPanel(value) { $('#' + value + '> tbody > tr').each(function () { alert($(this).html()); $(this).find('td').e

我编写了这个javascript来获取一个表的Id,然后首先循环通过tr,然后循环通过td。我不知道写什么逻辑来获取td中下拉列表的选定值。并非所有tds都有下拉列表

这是我的javascript

function submitPanel(value) {
    $('#' + value + '> tbody  > tr').each(function () {
        alert($(this).html());
        $(this).find('td').each(function () {
            alert($(this).html());
        })
    });
}
哪个输出:

该表采用MVC 4剃须刀制作

@model IMEModels.InterviewManagement.InterviewManagement
<hr />
@using (Html.BeginForm("SubmittedInterviews", "InterviewManagement", FormMethod.Post))
{
    if (Model.InterviewSchedules.Count > 0)
    {
        <table>
        <tr>
        <td>@Html.Label("Show dates without Chair or Co-panelist") </td>
        <td>@Html.RadioButton("Show dates without Chair or Co-panelist", new {Id = "rdoShow" })</td>
        </tr>
        </table>


        for (int i = 0; i < Model.Centres.Count; i++)
        {
    @Html.Label(Model.Centres[i].CentreName)

            for (int ii = 0; ii < Model.Centres[i].Locations.Count; ii++)
            {
    @Html.Label(Model.Centres[i].Locations[ii].LocationName)

                for (int iii = 0; iii < Model.Centres[i].Locations[ii].InterviewDates.Count; iii++)
                {

    var ChairList = Model.Interviewers.Join(Model.DatePreferences, m => m.InterviewerId, d => d.InterviewersInterviewerId, (m, d) => new
    {
        Interviewer = m,
        DatePreferences = d
    })
    .Where(d => d.DatePreferences.LocKey == Convert.ToString(Model.Centres[i].Locations[ii].LocationKey) && d.Interviewer.IsChair && d.DatePreferences.Date == Model.Centres[i].Locations[ii].InterviewDates[iii].Date)
    .GroupBy(x => new { x.Interviewer.InterviewerId, x.Interviewer.Name })
    .ToDictionary(a => a.Key.InterviewerId, b => b.Key.Name);

    var NonChairList = Model.Interviewers.Join(Model.DatePreferences, m => m.InterviewerId, d => d.InterviewersInterviewerId, (m, d) => new
    {
        Interviewer = m,
        DatePreferences = d
    })
    .Where(d => d.DatePreferences.LocKey == Convert.ToString(Model.Centres[i].Locations[ii].LocationKey) && d.DatePreferences.Date == Model.Centres[i].Locations[ii].InterviewDates[iii].Date)
    .GroupBy(x => new { x.Interviewer.InterviewerId, x.Interviewer.Name })
    .ToDictionary(a => a.Key.InterviewerId, b => b.Key.Name);

    @:<div class="date-wrap  @(ChairList.Count == 0 || NonChairList.Count == 0 ? "nochairspanelists" : "chairspanelists") >

    if (NonChairList.Count == 0)
    {
        NonChairList.Add(new Guid(), "No panelists available.");
    }

    if (ChairList.Count == 0)
    {
        ChairList.Add(new Guid(), "No panelists available.");
    }

    @Html.Label(Model.Centres[i].Locations[ii].InterviewDates[iii].Date.ToLongDateString())

    <table id="tbl@(Model.Centres[i].Code + "-" + Model.Centres[i].Locations[ii].LocationKey + "-" + Model.Centres[i].Locations[ii].InterviewDates[iii].Date.Ticks)" class="tblInterviewManager">
        <tr>
            <td>
                Chair
            </td>
            <td>
                Co-panelist
            </td>
            <td></td>
        </tr>
        <tr>
            <td>
                @Html.DropDownListFor(m => m.InterviewSchedules[iii].ChairId, new SelectList(ChairList, "Key", "Value"))
                <br />
            </td>
            <td>
                @Html.DropDownListFor(m => m.InterviewSchedules[iii].CofacilitatorId, new SelectList(NonChairList, "Key", "Value"))
            </td>
             @if (ChairList.ElementAt(0).Value == "No panelists available." || NonChairList.ElementAt(0).Value == "No panelists available.")
            {
            <td>
            <input type="submit" value="Save panel"  disabled="disabled" />
            </td>
             }
             else
             {
            <td>
            <input type="button" value="Save panel" id="btnSubmit" onclick="return submitPanel('tbl@(Model.Centres[i].Code + "-" + Model.Centres[i].Locations[ii].LocationKey + "-" + Model.Centres[i].Locations[ii].InterviewDates[iii].Date.Ticks)');"/>
            </td>
             }
        </tr>
    </table>      
    @:</div>
                }
            }

    <br />
        }
        <div class="clear"></div>

    <hr />
    }
}
@model.IMEModels.InterviewManagement.InterviewManagement

@使用(Html.BeginForm(“SubmittedInterviews”,“面试管理”,FormMethod.Post)) { 如果(Model.InterviewSchedules.Count>0) { @Html.Label(“在没有主席或共同小组成员的情况下显示日期”) @RadioButton(“在没有主席或共同小组成员的情况下显示日期”,新建{Id=“rdoShow”}) 对于(int i=0;im.occountersid,d=>d.occountersintervicewide,(m,d)=>new { 采访者=m, 日期首选项=d }) 其中(d=>d.DatePreferences.LocKey==Convert.ToString(Model.centers[i].Locations[ii].LocationKey)和&d.octactor.IsChair&&d.DatePreferences.Date==Model.centers[i].Locations[ii].InterviewDates[iii].Date) .GroupBy(x=>new{x.conceptor.conceptor-id,x.conceptor.Name}) .ToDictionary(a=>a.Key.octacher ID,b=>b.Key.Name); var NonChairList=Model.accounters.Join(Model.DatePreferences,m=>m.occountersid,d=>d.occountersintervicewide,(m,d)=>new { 采访者=m, 日期首选项=d }) 其中(d=>d.DatePreferences.LocKey==Convert.ToString(Model.centers[i].LocationKey[ii].LocationKey)和&d.DatePreferences.Date==Model.centers[i].Locations[ii].InterviewDates[iii].Date) .GroupBy(x=>new{x.conceptor.conceptor-id,x.conceptor.Name}) .ToDictionary(a=>a.Key.octacher ID,b=>b.Key.Name); @:用于直接获取
表中的
选项

function submitPanel(value) {
    $('#' + value + ' select').each(function () {
        alert($(this).val());        
    });
}
选择作为给定祖先的后代的所有元素 一个元素的后代可以是一个孩子,孙子, 那个元素的曾孙,等等


哇,这是一种更容易获得我想要的东西的方法。我会在允许的情况下将其标记为正确。jQuery简化了它,您可以在这里了解更多关于jQuery的信息,问题是我只在需要时才使用jQuery,所以我忘了我可以用它做什么。感谢您的帮助。在所有具有下拉列表的td
中添加一个类,然后调用
。each()`在该选择器上,检查表上每个下拉列表上的选定值。