0

我有一个生成的表格,当按下第 6 列上的按钮以获取行中的第一个单元格值并将其发送到覆盖页面时,覆盖页面将进行一些计算,这将需要一些时间并显示分数,我想用该分数替换第 6 列按钮。

处理时我无法让 page2.php 在叠加层中显示(我使用此处的弹出窗口)

这是我到目前为止所达到的

<tbody>
    <?php foreach ($rows as $row_number => $columns): ?>
      <?php
        $row_class = 'row-' . ($row_number + 1);
        if ($row_number == 0) {
          $row_class .= ' row-first';
        }
        if (count($rows) == ($row_number + 1)) {
          $row_class .= ' row-last';
        }
      ?>
      <tr class="<?php print $row_class; ?>">
        <?php foreach ($columns as $column_number => $item): ?>
          <td class="<?php print 'col-'. ($column_number + 1); ?>"  >
                <?php print $item; ?>
          </td>
        <?php endforeach; ?>
<td>
<?php print $dnsearch; ?> 
</td>
<td>

<button id="my-button">Get Score</button>
<div id="element_to_pop_up">
    <a class="bClose">x<a/>

这里应该 page2.php 从脚本接收变量并进行处理并返回数据(分数)以替换单击的按钮

 </div>



    </td>
          </tr>
        <?php endforeach; ?>
      </tbody>
    </table>


    <script type="text/javascript">
    $(":button").click(function (e) {
    e.preventDefault();
    $('#element_to_pop_up').bPopup();
    $.post("page2.php", {val: $(this).closest('tr').find('td:eq(0)').text()}, function(returned_data){
    //    alert(returned_data); 
          $(e.target).closest("td").text(returned_data); // to replace button with score
       });

    });

    </script>
4

1 回答 1

0

单击按钮时,将第一行的值发送到 jquery 并对第二页进行 ajax 调用,并在第二页的响应中进行所需的计算,用结果替换按钮查找示例。

http://api.jquery.com/jQuery.ajax/

把你的按钮放在这样的范围内

<span id="result">
<button id="my-button">Get Score</button></span>

然后在你的响应处理jQuery中把这个

$("#result").html(you calculation result jquery variable);
于 2013-01-16T16:48:40.703 回答