【问题标题】:How do I make a calendar table > td a selectable form element?如何使日历表 > td 成为可选择的表单元素?
【发布时间】:2016-09-17 19:37:52
【问题描述】:

我正在制作一个活动预订表格,我需要用户能够单击日历上的表格单元格来选择他们的开始日期。

遗憾的是,我对 Javascript 的了解有限,在过去的几个月里我把所有的精力都放在了 PHP 上。

据我所知,我需要执行某种 ajax 操作来“获取”日期(例如 2016/9/16)并将其作为 POST 数据与我的其他表单数据一起发送。谢天谢地,我参加了关于 udemy 的 AJAX 课程。

我目前所拥有的。

这是我的表格

日历是简单的表格,每一天都是指向特定页面的链接,URL 中有数据,例如example/2016/5/4

这是我生成日历的方式...

{table_open}<table id="tt-calendar">{/table_open}

                    {heading_row_start}<tr>{/heading_row_start}

                        {heading_previous_cell}
                            <th class="text-center">

                            </th>
                        {/heading_previous_cell}

                        {heading_title_cell}
                            <th class="text-center" colspan="{colspan}">
                                <h4>
                                    {heading}
                                </h4>
                            </th>
                        {/heading_title_cell}

                        {heading_next_cell}
                            <th class="text-center">

                            </th>
                        {/heading_next_cell}

                    {heading_row_end}</tr>{/heading_row_end}
                    {week_row_start}<tr>{/week_row_start}

                        {week_day_cell}
                            <td>
                                <strong>
                                    {week_day}
                                </strong>
                            </td>
                        {/week_day_cell}

                    {week_row_end}</tr>{/week_row_end}
                    {cal_row_start}<tr>{/cal_row_start}

                        {cal_cell_start}<td>{/cal_cell_start}

                        {cal_cell_start_today}<td id="tt-calendar-today">{/cal_cell_start_today}

                        {cal_cell_start_other}<td id="tt-calendar-test">{/cal_cell_start_other}

                        {cal_cell_content}
                            <a id="tt-calendar-event" href="' .  base_url() . 'schedule/today/' . $year . '/' . $month . '/{day}/' . $student_id . '">
                                {day}
                            </a>
                        {/cal_cell_content}

                        {cal_cell_content_today}
                            <a href="' .  base_url() . 'schedule/today/' . $year . '/' . $month . '/{day}/' . $student_id . '">
                                {day}
                            </a>
                        {/cal_cell_content_today}

                        {cal_cell_no_content}
                            <a href="' .  base_url() . 'schedule/today/' . $year . '/' . $month . '/{day}/' . $student_id . '">
                                {day}
                            </a>
                        {/cal_cell_no_content}

                        {cal_cell_no_content_today}
                            <a href="' .  base_url() . 'schedule/today/' . $year . '/' . $month . '/{day}/' . $student_id . '">
                                {day}
                            </a>
                        {/cal_cell_no_content_today}

                        {cal_cell_blank}&nbsp;{/cal_cell_blank}

                        {cal_cell_other}{day}{/cal_cel_other}

                        {cal_cell_end}</td>{/cal_cell_end}

                        {cal_cell_end_today}</td>{/cal_cell_end_today}

                        {cal_cell_end_other}</td>{/cal_cell_end_other}

                    {cal_row_end}</tr>{/cal_row_end}

                {table_close}</table>{/table_close}

那么...如何使日历“td”元素成为可选择的“表单”元素,该元素能够将其 POST 数据与表单发布数据的其余部分一起传递? 额外文章/教程的链接将不胜感激...

【问题讨论】:

  • 你的想法很复杂。不要试图将表格单元格“制作”成其他任何东西,而只需在表单中为日期设置一个隐藏字段即可。然后单击表格单元格,用相应的值填充该隐藏字段。 (或者首先将其设置为日期输入字段。然后让日期选择器处理其余部分。在尚不支持它的浏览器中需要为日期选择器使用 polyfil。)
  • 嘿,这真是太棒了。真是个好主意!

标签: javascript php html ajax codeigniter


【解决方案1】:

这是一个你可能会用到的教程的链接

https://code.tutsplus.com/tutorials/codeigniter-from-scratch-the-calendar-library--net-9570

如果这不起作用,请使用这个

https://www.youtube.com/watch?v=qMsEAtXtE2g

【讨论】:

    猜你喜欢
    • 2016-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    相关资源
    最近更新 更多