简体   繁体   中英

How to update table cell value in Jquery

I ma new to jquery. I would like to update the table cell from Jquery.
The Php is as below. For example I would like to update "firsttotal" with a different value. Please help.

<tr>
                        <td class="Left">Total</td>
                        <td></td>
                        <td id="firsttotal"><?php echo number_format('%.2n', $Total_Calculated_Cash); ?></td>
                        <td id="cashcalculator_total"><a href="#"><?php echo number_format($Total_Actual_Cash, 2); ?></a></td>
                        <td><?php echo number_format($Total_Calculated_Other, 2); ?></td>
                        <td><?php echo number_format($Total_Actual_Other, 2); ?></td>
                    </tr>

Get the td element and set the value like so:

<script type="text/javascript">
    var newValue = 6;
    $("#firsttotal").text(newValue);
</script>
$('td#firsttotal').html(value);

要么

$('td#firsttotal').text(value)
jQuery('#firsttotal').html("new Value");
$('td#firsttotal').text(value)

so something like this would work

$('td#firsttotal').text("test")

If you wanted to add HTML tags into it then you can use this

$('td#firsttotal').html("<p>test</p>")

since anchor is inside TD, you should use jQuery('td#cashcalculator_total a')

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.pack.js"></script>
<script type="text/javascript">
    jQuery(function() {
        jQuery('td#cashcalculator_total a').html('XXX');
    });
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM