在块计划中使用jQuery合并HTML表格单元格

时间:2019-02-11 09:18:33

标签: c# jquery html asp.net-mvc

我如何实现根据end_time合并单元格的目标?

我的html:

<table border="1" style="text-align:center;" align="center">
    <tr style="text-align:center">
        <th style="text-align:center; background-color: #3a6070; color: #FFF; padding: 4px 30px 4px 8px;">Time</th>
        <th style="text-align:center; background-color: #3a6070; color: #FFF; padding: 4px 30px 4px 8px;">Monday</th>
        <th style="text-align:center; background-color: #3a6070; color: #FFF; padding: 4px 30px 4px 8px;">Tuesday</th>
        <th style="text-align:center; background-color: #3a6070; color: #FFF; padding: 4px 30px 4px 8px;">Wednesday</th>
        <th style="text-align:center; background-color: #3a6070; color: #FFF; padding: 4px 30px 4px 8px;">Thursday</th>
        <th style="text-align:center; background-color: #3a6070; color: #FFF; padding: 4px 30px 4px 8px;">Friday</th>
        <th style="text-align:center; background-color: #3a6070; color: #FFF; padding: 4px 30px 4px 8px;">Saturday</th>
        <th style="text-align:center; background-color: #3a6070; color: #FFF; padding: 4px 30px 4px 8px;">Sunday</th>
    </tr>

 <!--1:00-1:30-->
            <tr>
                <td>1:00-1:30</td>
                <td id="T0100Monday"></td>
                <td id="T0100Tuesday"></td>
                <td id="T0100Wednesday"></td>
                <td id="T0100Thursday"></td>
                <td id="T0100Friday"></td>
                <td id="T0100Saturday"></td>
                <td id="T0100Sunday"></td>  
            </tr>

 <!--1:30-2:00-->
            <tr>
                <td>1:30-2:00</td>
                <td id="T0130Monday"></td>
                <td id="T0130Tuesday"></td>
                <td id="T0130Wednesday"></td>
                <td id="T0130Thursday"></td>
                <td id="T0130Friday"></td>
                <td id="T0130Saturday"></td>
                <td id="T0130Sunday"></td> 
            </tr>
</table>

这是我的脚本:

<script>
        $(function () {
            @foreach (var y in Model)
            {
                if (y.avail_time_starts == "T0100" && y.time_type == "PM" && (y.avail_day == "Mon" || y.avail_day == "MWF"))
                {
                    ViewContext.Writer.Write(string.Format("$(\"#T0100Monday\").text('{0} {1}');", y.subject_code,y.room_code));
                    
                }
                if (y.avail_time_starts == "T0100" && y.time_type == "PM" && (y.avail_day == "Tue" || y.avail_day == "TTH"))
                {
                    ViewContext.Writer.Write(string.Format("$(\"#T0100Tuesday\").text('{0} {1}');", y.subject_code, y.room_code));
                }
                if (y.avail_time_starts == "T0100" && y.time_type == "PM" && (y.avail_day == "Wed" || y.avail_day == "MWF"))
                {
                    ViewContext.Writer.Write(string.Format("$(\"#T0100Wednesday\").text('{0} {1}');", y.subject_code, y.room_code));
                }
                if (y.avail_time_starts == "T0100" && y.time_type == "PM" && (y.avail_day == "Thu" || y.avail_day == "TTH"))
                {
                    ViewContext.Writer.Write(string.Format("$(\"#T0100Thursday\").text('{0} {1}');", y.subject_code, y.room_code));
                }
                if (y.avail_time_starts == "T0100" && y.time_type == "PM" && (y.avail_day == "Fri" || y.avail_day == "MWF"))
                {
                    ViewContext.Writer.Write(string.Format("$(\"#T0100Friday\").text('{0} {1}');", y.subject_code, y.room_code));
                }
            }
        });
    
    </script>

my controller:

 public ActionResult Index()
    {
        var model = from d in db.sis_subject_offerings where d.section_code == "G1" select d;
        return View(model.ToList());
    }

    SCI.Entities.Models.SCIContext db = new SCI.Entities.Models.SCIContext();

}

计划是:MWF下午1:00-2:00 我的代码的结果是输出仅停留在1:00-1:30行 我想合并1:00-1:30和1:30-2:00的2行单元格  我希望输出将是这样的:

enter image description here

(我不知道从哪里开始合并代码,请帮忙)

0 个答案:

没有答案