代码之家  ›  专栏  ›  技术社区  ›  Treby

HTML:在表格的单元格中禁用单击

  •  0
  • Treby  · 技术社区  · 15 年前

    我有一张用日历做成的桌子。我想知道如何才能禁用该单元格下的所有单击。因为我的论点是。任何小于当前日期的内容都将被禁用。 这意味着该日期td所有子项的所有单击功能将被禁用(添加、编辑、查看列表)

    1 回复  |  直到 15 年前
        1
  •  1
  •   Joel    15 年前

    在click事件的事件处理程序上,可以通过返回false来防止链接跟踪。

    超级简化:

    function myClickHandler(e)
    {
        var target = e.srcElement;
        if (!target)
            target = e.target;
    
        var sdate = new Date(target.parent.getAttribute("rel"));
        if (sdate < currentdate) // doesn't take into account time!!
            return false;
    }
    

    给定以下标记:

    <table>
        <tbody>
            <tr>
                <td class="day" rel="1/1/2010">
                    <a href="edit" onclick="return myClickHandler(e)">Edit this day</a>
                </td>
                ...
            </tr>
        </tbody>
    </table>