2017-04-09 94 views
1

我使用mysql的动态数据创建表。他似乎是: screen从动态表中获取值mysql php

当我点击第二行的删除按钮,并用id的值发出警报js时,他从第一行中保存了id,而不是保存在我cliqued的行中。

我的看法:

$('.Btrash').click(function() { 
 

 
    //var id_stream = $('#id_stream').val(); 
 
    var id_stream = $('#id_stream').attr('value'); 
 
    var id_compte = $('#id_compte').val(); 
 

 
    alert(id_stream); 
 
});
<div class="row" id="Tstream"> 
 
     <table class="table table-striped table-bordered table-list"> 
 
      <thead> 
 
       <tr> 
 
        <th>Feeds</th> 
 
        <th>Data request</th> 
 
        <th>Begin Stream</th> 
 
        <th>End Stream</th> 
 
        <th><em class="fa fa-cog"></em></th> 
 
        <th>Status</th> 
 
        <th>Access to Data</th> 
 
       </tr> 
 
      </thead> 
 
      <tbody > 
 
       <?php foreach ($aAllRequestByIdUser as $aRequestByIdUser) : ?> 
 
       <tr> 
 
        <td class="vert-align"> 
 
        <input type="hidden" id="id_compte" value="<?= $iIdCompte ?>"> 
 
        <input type="text" id="id_stream" value="<?= $aRequestByIdUser['id_Stream'] ?>"> 
 
       ...

我的警报一直显示74 你能帮我找到一个解决办法?

谢谢

回答

0

首先让我解释一下jQuery选择器。你

var id_stream = $('#id_stream').attr('value'); 

的这个代码选择所有#id_stream的ID项目,并返回一个值。

如果你想获得点击的行的ID,那么你应该先选择行。但是由于你没有分享你的其他代码,我只能假设其余的。有几种方法可以这样做,这是其中之一。

1)获取的$(本)>

2)母公司然后得到它

3中的第一元素),最后发现输入并获得VAL()。

或者你可以通过Jquery的最接近的功能来做到这一点。但正如我所说,首先我需要看看你的代码的其余部分。