douyanning3724
douyanning3724
2011-05-03 17:22

仅更新<col>中的值

So I really need to know if it's possible to update the values under a specific column on a table.

<table>
    <col with="auto">
    <col with="auto">
    <col with="auto" id="update_me">

<?php
for(hundreds of lines){
?>
    <tr>
    <td>something 0</td>
    <td>something 1</td>
    <td>Need to update</td>
    <tr>
<?php
}
?>

I will be using:

<script>
$(document).ready(function() {
$("#update_me").load("response.php");
var refreshId = setInterval(function() {
$("#update_me").load('response.php');
}, 6000);
$.ajaxSetup({ cache: false });
});
</script>

The php will only generate the values from the specific column!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • douzhang5984 douzhang5984 10年前
    <script>
       $(document).ready(function() {
          var refreshId = setInterval(function() {
             $.getJSON('response.php', function(data) {
                $.each(data, function(index, value) {
                   $('#value'+index).html(value).show();
            });
          });       
          }, 3000);
          $.ajaxSetup({ cache: false});
       });
    </script>
    
    点赞 评论 复制链接分享
  • dongsonglian7303 dongsonglian7303 10年前

    I don't understand why nobody has suggested

    jQuery("td:nth-child(" + column_number + ")").each(function(row_number)
    { 
        //Do something to this row's cell in column "column_number" 
    });
    
    点赞 评论 复制链接分享
  • douzong3599 douzong3599 10年前

    I think this is more what you are looking for:

    My Table
    <table>
    <tr>
        <td width="auto"> </td>
        <td width="auto"> </td>
        <td width="auto" id="update_me1"></td>
    <tr>
    <tr>
        <td width="auto"> </td>
        <td width="auto"> </td>
        <td width="auto" id="update_me2"></td>
    <tr>
    <tr>
        <td width="auto"> </td>
        <td width="auto"> </td>
        <td width="auto" id="update_me3"></td>
    <tr>
    </table>
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
    <script>
    $(document).ready(function() {
        $("#update_me").load("response.php");
        var arr = ['1','2','3'];
    
        var refreshId = setInterval(function() {
            $.each(arr, function() {
              $('#update_me' + this).load('response.php');  
            });
        }, 6000);
        $.ajaxSetup({ cache: false });
    });
    </script>
    

    UPDATE: This javascript calls the response.php multiple times. So for each ID in arr it will call the script. If you pass the ID to the script (as described in my comments below), you can limit the data returned by each request:

    $('#update_me' + this).load('response.php?id' + this);

    This means that for each iteration of arr, you will be calling response with the appropriate id:

    '#update_me1' is populated with the results from 'response.php?id=1'
    '#update_me2' is populated with the results from 'response.php?id=2'
    '#update_me3' is populated with the results from 'response.php?id=3'
    etc...
    

    Otherwise, you need to call response.php once and parse the data in the javascript. Those are the only options you have.

    点赞 评论 复制链接分享

相关推荐