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

如何在整个td元素上设置链接区域可点击?

  •  0
  • harunB10  · 技术社区  · 6 年前

    我有一些由链接组成的菜单项:

    <tr> 
    <td> <a href ="#" onclick="selectItem(this)" style="text-decoration: none">' + response[index] + ' </a> </td> 
    </tr>
    

    但它只能在某些地方点击 <td> (列)。我如何设置这是可以点击整个列宽和高度?

    4 回复  |  直到 6 年前
        1
  •  1
  •   Void Spirit    6 年前
    <tr> 
       <td onclick="selectItem(this.textContent)" style="cursor:pointer">' + response[index] + ' </td> 
    </tr>
    
        2
  •  0
  •   Lazar Nikolic    6 年前
      <td style="position: relative;"> 
        <a href ="#" style="text-decoration: none; position: absolute; left: 0; right: 0; top: 30%">' + response[index] + ' </a> 
      </td>
    

    顶部:30%可以调整根据字体大小或填充或其他css规则,你有。

        3
  •  0
  •   serge    6 年前

    你可以用 display: block 在单元格中完全填充 a 元素:

    table {width: 100%;}
    tr {background: blue; border: 1px red solid;}
    a.full-link {display: block; background: yellow; text-decoration: none;}
    <table>
    <tr> 
    <td>
      <a class="full-link" onclick="selectItem(this)" href="">your text </a> 
    </td> 
    </tr>
    </table>
        4
  •  0
  •   Pang Ajmal PraveeN    6 年前
    1. 尝试在JavaScript中捕获/冒泡事件(只提示开始)。