How are cells of a table impacted by declaring an event in a col element?

早过忘川 提交于 2020-01-03 10:18:02

问题


When an event, such as onclick, is declared in a col element for an HTML table does that event impact the cells referenced by the col element? Is the event ignored? Does something else happen?


回答1:


Great question.

The spec says:

<!ATTLIST COL                          -- column groups and properties --
  %attrs;                              -- %coreattrs, %i18n, %events ---

where %events says:

<!ENTITY % events
 "onclick     %Script;       #IMPLIED  -- a pointer button was clicked --
  ondblclick  %Script;       #IMPLIED  -- a pointer button was double clicked--
  onmousedown %Script;       #IMPLIED  -- a pointer button was pressed down --
  onmouseup   %Script;       #IMPLIED  -- a pointer button was released --
  onmouseover %Script;       #IMPLIED  -- a pointer was moved onto --
  onmousemove %Script;       #IMPLIED  -- a pointer was moved within --
  onmouseout  %Script;       #IMPLIED  -- a pointer was moved away --
  onkeypress  %Script;       #IMPLIED  -- a key was pressed and released --
  onkeydown   %Script;       #IMPLIED  -- a key was pressed down --
  onkeyup     %Script;       #IMPLIED  -- a key was released --"
  >

So yes, it appears events are supposed to be supported for the tds.

However "supposed to" is a far cry from "does". The only way to know is to test in all browsers and hope it works in future browsers too.

On second thought, just use event delegation and bind once to the parent table instead. That will work now and forever more.



来源:https://stackoverflow.com/questions/1406399/how-are-cells-of-a-table-impacted-by-declaring-an-event-in-a-col-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!