duanhanglekr37902 2015-04-04 10:25
浏览 49
已采纳

使用jquery获取表中输入框的值

I have a table containing multiple rows of input boxes. Entire table and its contents are created dynamically using jQuery Post. Each tr in the table has 7 td and the first td contains a radio button and remaining have text input boxes with values. User has to change the values in the text boxes and click on radio button to update the same. how to get the value if input boxes in the selected row?

I used following function to pop an alert message

jQuery(document).delegate("[name='edit']", "click",function (e) {
alert("clicked");}

This is working. I want to get values of input boxes using this. closest tr input . But do not know the syntax. Please help

the script for creating the table is like this:

echo'<form id="shiftentry" name="shiftentry" >';


 echo "Date:<input id=shiftdate value='".$date."'/>"; 
 echo "Unit:<input id=shiftdate value='".$unit."'/>";
 echo "Shift:<input id=shiftdate value='".$shift."'/><br/>";

   echo "<table><tr><th>No</th><th>Ele</th><th>Location</th><th>Drate </th><th>H3 Val </th><th>Part </th>   <th>Iod</th><th>Cont. </th></tr>";
            while($row2=mysql_fetch_array($result_sec))
                { 
                echo "<tr>";
     echo "<td><input name='edit' type='radio'/></td>";
                echo "<td>".++$rc."</td>";
                echo "<td><input size='5' id='".$row2['ele']."' value='".$row2['ele']."' /></td>";
                echo "<td><input id='".$row2['loc_id']."' value='".$row2['loc']."' /></td>";
                echo "<td><input size='5' id='drate".$rc."'  value='".$row2['drate']."'/></td>";
                echo "<td><input size='5' id='h3".$rc."' value='0' /></td>";
                echo "<td><input size='5' id='part".$rc."' value='0' /></td>";
                echo "<td><input size='5' id='iod".$rc."' value='0' /></td>";
                echo "<td><input size='5' id='cont".$rc."' value='0' /></td>";
                echo "</tr>";
            }



  echo " </table>";



   echo '<div align="center">';
   echo '<input type="submit" id="submit2" name="submit2" value="Submit" width="30" />';
   echo '</div>';

 echo '</form>';
  • 写回答

1条回答 默认 最新

  • dsmlf1207915 2015-04-04 11:19
    关注

    Take a look on .closest() and :eq() selector.

    jQuery(document).delegate("input[name='edit']", "click",function (e) {
    
        // Will return the Parent Row of clicked input
        var _tr = $(this).closest('tr');
    
        // You have 9 td in particular row 
        // Let's access the 7th input box: <input size='5' id='iod".$rc."' value='0' />
        $('td:eq(7) input', _tr).val(); // will return its value
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来