0

是)我有的:

<table class="sortable table table-hover table-bordered">
  <thead>
  <tr>
    <th>CPU</th>
    <th>Speed</th>
    <th>Cores</th>
    <th>TDP</th>
    <th>Preformace</th>
    <th>Overclocing</th>
    <th>Price</th>
    <th>Buy</th>
  </tr>
  </thead>
  <tbody>
  <?php $i=0 ;
    do {
    $preformace = $row_Procesory['Preformace'];
    $over = $row_Procesory['Overclocing'];
    $i++; ?>
    <tr>
    <td><?php echo $row_Procesory['CPU']; ?></td>
    <td><?php echo $row_Procesory['Speed']; ?></td>
    <td><?php echo $row_Procesory['Cores']; ?></td>
    <td><?php echo $row_Procesory['TDP']; ?></td>
    <td><?php echo "
    <script type='text/javascript'>
    $(document).ready(function() {
    $('#progressbarP$i').height(10).progressbar({
                                    value : 1
                                    });
    $('#progressbarP$i .ui-progressbar-value').animate(
    {width: '$preformace%'},{queue: false});
    });
    </script>
    <div id='progressbarP$i' title='$preformace'></div>  
    ";?></td>

    <td><?php echo "
    <script type='text/javascript'>
    $(document).ready(function() {
    $('#progressbarO$i').height(10).progressbar({
                                    value : 1
                                    });             
    $('#progressbarO$i .ui-progressbar-value').animate({
        width: '$over%'
        }, 1000);
    });
    </script>
    <div id='progressbarO$i' title='$over'></div>  
    ";?></td>

    <td><?php echo $row_Procesory['Price']; ?></td>
    <!-- BUTTON SECTION -->
   <td><?php echo "<button class='btn btn-success' type='button' align='CENTER'>Add</button>";?></td>
  </tr>
    <?php } while ($row_Procesory = mysql_fetch_assoc($Procesory)); ?>
</tbody>
</table>

基本上我循环通过mysql并显示行。在 preformace 和超频列中,我显示了带有 mysql 值的动画 jquery progresbar。我还使用 bootstrap 和 sortable.js 使表格可排序。

它的样子:

我想要什么:当我单击添加按钮时,处理器的名称将作为变量发送到 test.php。我什至不知道如何使用 jquery 定位名称元素:D

4

2 回答 2

0

如果我在这里理解您的问题,可以提供帮助

<table class="sortable table table-hover table-bordered">
  <thead>
  <tr>
    <th>CPU</th>
    <th>Speed</th>
    <th>Cores</th>
    <th>TDP</th>
    <th>Preformace</th>
    <th>Overclocing</th>
    <th>Price</th>
    <th>Buy</th>
  </tr>
  </thead>
  <tbody>
  <?php $i=0 ;
    do {
    $preformace = $row_Procesory['Preformace'];
    $over = $row_Procesory['Overclocing'];
    $i++; ?>
    <tr>
    <td><?php echo $row_Procesory['CPU']; ?></td>
    <td><?php echo $row_Procesory['Speed']; ?></td>
    <td><?php echo $row_Procesory['Cores']; ?></td>
    <td><?php echo $row_Procesory['TDP']; ?></td>
    <td><?php echo "
    <script type='text/javascript'>
    $(document).ready(function() {
    $('#progressbarP$i').height(10).progressbar({
                                    value : 1
                                    });
    $('#progressbarP$i .ui-progressbar-value').animate(
    {width: '$preformace%'},{queue: false});
    });
    </script>
    <div id='progressbarP$i' title='$preformace'></div>  
    ";?></td>

    <td><?php echo "
    <script type='text/javascript'>
    $(document).ready(function() {
    $('#progressbarO$i').height(10).progressbar({
                                    value : 1
                                    });             
    $('#progressbarO$i .ui-progressbar-value').animate({
        width: '$over%'
        }, 1000);
    });
    </script>
    <div id='progressbarO$i' title='$over'></div>  
    ";?></td>

    <td><?php echo $row_Procesory['Price']; ?></td>
    <!-- BUTTON SECTION -->
   <td><?php echo "<button class='btn btn-success pro_btn' processor = '".$row_Procesory['CPU']."'  type='button' align='CENTER'>Add</button>";?></td>
  </tr>
    <?php } while ($row_Procesory = mysql_fetch_assoc($Procesory)); ?>
</tbody>
</table>

该解决方案(处理器属性)是为了避免选择器,如果您需要,我们可以提供其他选择器

$('.pro_btn').die('click').live('click',function(e){
     var name = $(this).attr('processor');
     $.post('test.php',{'processor_name':name}, function(response) {
    // log the response to the console
         console.log("Response: "+response);
     });

}); 

如果您不想使用该属性,您可以执行以下操作

var name = $(this).closest('tr').find('td:first').text();

我希望这可以帮助:)

于 2013-02-15T21:24:01.250 回答
0

捕获点击事件并找到最接近的“tr”,然后找到该“tr”的第一个“td”。那将是这样的:

$(this).closest('tr').find('td:first').text();

或者获取按钮的父项,这将是 td,它们是 td 的父项。那将是tr。最后得到第一个 td。

$(this).parent().parent().find('td:first').text();

或者只是为您的按钮添加一个附加属性,然后获取值。

$(this).attr('processor');
于 2013-02-15T21:37:12.200 回答