Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.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 如何通过单击表格单元格按钮获取行号?_Javascript_Php_Jquery_Mysql - Fatal编程技术网

Javascript 如何通过单击表格单元格按钮获取行号?

Javascript 如何通过单击表格单元格按钮获取行号?,javascript,php,jquery,mysql,Javascript,Php,Jquery,Mysql,我正在用js度过一段非常艰难的时间。我花了一天的时间来解决一个问题。我不知道我什么时候才能度过这段艰难的时间。我只是想从表单元格按钮中获取一个表行数。意思是说,一个表有5行数据是从数据库中获取的。每行包含一个按钮。如果我单击一个按钮,它将返回或返回显示此按钮所属的行号。 我的html和php代码---- 如果你们能帮我的话 使用类: $(函数(){ $('button.idna5')。在('click',function()上{ 警报($(this).closest('tr').index(

我正在用js度过一段非常艰难的时间。我花了一天的时间来解决一个问题。我不知道我什么时候才能度过这段艰难的时间。我只是想从表单元格按钮中获取一个表行数。意思是说,一个表有5行数据是从数据库中获取的。每行包含一个按钮。如果我单击一个按钮,它将返回或返回显示此按钮所属的行号。 我的html和php代码----

如果你们能帮我的话

使用类

$(函数(){
$('button.idna5')。在('click',function()上{
警报($(this).closest('tr').index())
})
})

供应商图片路径
供应商标题
供应商添加日期
卖方机构
加一道菜
正文
正文
正文
正文
添加
正文
正文
正文
正文
添加
正文
正文
正文
正文
添加

您的输出为?第一个输出为nothing,第二个输出始终显示为0
<table class="w3-table-all w3-margin-top" id="myTable">
<tr>
  <th style="width:22.5%;">Vendor Picture Path</th>
  <th style="width:22.5%;">Vendor Heading</th>
  <th style="width:22.5%;">Vendor Adding Date</th>
  <th style="width:22.5%;">Vendor Body</th>
  <th style="width:10%;">Add A Course</th>
</tr>
<?php

mysql_connect("host", "user", "pass")or die("cannot connect to server"); 
    mysql_select_db("db name")or die("cannot select DB");
    $sql = "sql";
    $result = mysql_query($sql);

    while($row=mysql_fetch_assoc($result))
    {
         echo '<tr>
         <td><div style="width:100%;height: 60px;margin: 0;padding: 0;overflow-y: scroll">'.$row["pic_path"].'</div></td>             
         <td><div onclick="getval(this)" class="cventablehead" id="ventablehead" style="width:100%;height: 60px;margin: 0;padding: 0;overflow-y: scroll; cursor: pointer; color:red;">'.$row["heading"].'</div></td>
         <td>'.$row["adding_date"].'</td>
         <td><div style="width:100%;height: 60px;margin: 0;padding: 0;overflow-y: scroll">'.$row["body"].'</div></td>
         <td><button onclick="idna5(this)">Add</button></td>
         </tr>';
    }
?>
  </table>
    function idna5(obj)
    {
       //alert(obj.index());--1st try
       alert($(obj).index());---2nd try
    }