doukeng1922 2015-02-20 08:54
浏览 31
已采纳

想要在jquery中显示表中特定行的文本框

I want to display the text box and its update button for which the row I click to edit my value.

enter image description here

In the above image When I click edit discount to change the discount value for the booking id 6, it shows all the text boxes in all rows like

enter image description here

<table id="example1" class="table table-bordered table-striped">
         <td><?php echo $bookedrow['status'];?></td>
       <td class="discount_val"><?php echo $bookedrow['discount'];?></td>
       <td class="new_discount">
         <input type="text" name="new_discount"/>
          <input class="btn btn-primary" id="update" name="update" value="Update" type="submit"/>
        </td>
       <td><a href="#" class="edit_discount">Edit discount</a></td>
            </tr>
               </tbody>
        </table>

JS code:

       $('.new_discount').hide();   
 $('.edit_discount').click(function(){
    $('.discount_val').hide(); 
    $('.new_discount').show();

 });

Now i want to get the text box and its button for which I'm selecting to update and that value will update for that particular id only.Guide me!!

  • 写回答

4条回答 默认 最新

  • douqu2712 2015-02-20 08:58
    关注

    You need to use DOM traversal functions to find just the element in the current row:

    $('.edit_discount').click(function() {
        var row = $(this).closest("tr");
        row.find(".discount_val").hide();
        row.find(".new_discount").show();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀