Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery在相邻的表单元格中触发链接_Javascript_Jquery_Html_Dom_Javascript Events - Fatal编程技术网

Javascript 使用jQuery在相邻的表单元格中触发链接

Javascript 使用jQuery在相邻的表单元格中触发链接,javascript,jquery,html,dom,javascript-events,Javascript,Jquery,Html,Dom,Javascript Events,我有一个HTML表,其中每行的第一个单元格包含文本,第二个单元格包含链接。像这样: <table id="foo"> <tr> <td>Some text</td> <td><a href="/path/to/file/"><img src="/path/to/image.jpg" /></a></td> </tr> ... </table&g

我有一个HTML表,其中每行的第一个单元格包含文本,第二个单元格包含链接。像这样:

<table id="foo">
  <tr>
    <td>Some text</td>
    <td><a href="/path/to/file/"><img src="/path/to/image.jpg" /></a></td>
  </tr>
  ...
</table>
这不管用。我尝试过几种不同的方法,但没有成功。我意识到我可以将文本和链接放在同一个单元格中,最终可能会这样做,但这只是我的页面实际情况的简化版本,需要做一些工作来重新调整内容


我做错了什么?

以编程方式单击链接不会转到
href
,只有本地(用户)单击才会,但您可以模拟它,如下所示:

$('#foo tr td:first-child').hover(...).click(
  function() {
    $(this).next().children().click();
  }
);
$('#foo tr td:first-child').hover(...).click(
  function() {
    window.location.href = $(this).next().children('a').attr('href');
  }
);

这会将设置为转到目标URL。

以编程方式单击链接不会转到
href
,只有本地(用户)单击才会,但您可以模拟它,如下所示:

$('#foo tr td:first-child').hover(...).click(
  function() {
    $(this).next().children().click();
  }
);
$('#foo tr td:first-child').hover(...).click(
  function() {
    window.location.href = $(this).next().children('a').attr('href');
  }
);
这会将设置为转到目标URL