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 遍历html表_Javascript_Jquery_Html - Fatal编程技术网

Javascript 遍历html表

Javascript 遍历html表,javascript,jquery,html,Javascript,Jquery,Html,我有一张这样结构的桌子: <table> <tr> <td><a href = "#">link1</a></td> <td><a href = "#">link2</a></td> <td><a href = "#">link3</a></td> <td><input typ

我有一张这样结构的桌子:

<table>
  <tr>
    <td><a href = "#">link1</a></td>
    <td><a href = "#">link2</a></td>
    <td><a href = "#">link3</a></td>
    <td><input type = "checkbox" onclick = "func()"></td>
  </tr>
</table>

function func(){
  //I have to alert link1 here. 
}

函数func(){
//我必须在这里通知link1。
}
有人能告诉我怎么做吗

提前谢谢


编辑1:存在多行相同类型的行,单击特定复选框应提醒相应的
文本。

您可以使用
jquery
执行此操作。只需更改
eq
的编号即可。所有带有
input
class
复选框的表都将运行。你可以玩它

$('.checkbox')。在('click',function()上{
var e=$(this).closest('table').find('td a');
警报(e.eq(0.text());
});
表格{
边框:1px纯红;
边缘底部:5px;
}

您可以使用
jquery
这样做。只需更改
eq
的编号即可。所有带有
input
class
复选框的表都将运行。你可以玩它

$('.checkbox')。在('click',function()上{
var e=$(this).closest('table').find('td a');
警报(e.eq(0.text());
});
表格{
边框:1px纯红;
边缘底部:5px;
}

因为您使用的是jQuery,所以请使用jQuery处理程序,在该处理程序中,您可以在同一行中找到
a

jQuery(函数($){
$(“#我的表格输入[type=“checkbox”]”)。更改(函数(){
警报($(this).closest('tr').find('td:first child a').text())
});
})

因为您使用的是jQuery,所以请使用jQuery处理程序,在该处理程序中,您可以在同一行中找到
a

jQuery(函数($){
$(“#我的表格输入[type=“checkbox”]”)。更改(函数(){
警报($(this).closest('tr').find('td:first child a').text())
});
})


alert($('td a:first').html())
是否会有多行
alert($('td a:first').html())
是否会有多行
$('td a')如果页面中存在任何其他表,该表是否与之匹配?不,我将在所有表中生效,只需在表中使用类,这样您就可以为该表指定特定的函数。@Anusha在表中使用类或ID以避免对其他表的影响s@mmativ谢谢:)
$('td a')如果页面中存在任何其他表,该表是否与之匹配?不,我将在所有表中生效,只需在表中使用类,这样您就可以为该表指定特定的函数。@Anusha在表中使用类或ID以避免对其他表的影响s@mmativ谢谢:)