Hướng dẫn auto sum javascript - javascript tổng hợp tự động

"; $("#keatas_" + a).append(data); }; } (a)); //this calculates values automatically calculateSum(); $("#packinglist_"+a).on("keydown keyup", function() { calculateSum(); }); function calculateSum() { var sum = 0; //iterate through each textboxes and add the values $("#packinglist_"+ a).each(function() { //add only if the value is number if (!isNaN(this.value) && this.value.length != 0) { sum += parseFloat(this.value); $(this).css("background-color", "#FEFFB0"); } else if (this.value.length != 0){ $(this).css("background-color", "red"); } }); $("input#netto_"+ a).val(sum.toFixed(2)); } }

Cập nhật mã HTML:

           if($_GET['mod'] == 'Buat Surat Jalan Keluar'){
        function romanNumerals($num) 
{
    $n = intval($num);
    $res = '';

    /*** roman_numerals array  ***/
    $roman_numerals = array(
                'M'  => 1000,
                'CM' => 900,
                'D'  => 500,
                'CD' => 400,
                'C'  => 100,
                'XC' => 90,
                'L'  => 50,
                'XL' => 40,
                'X'  => 10,
                'IX' => 9,
                'V'  => 5,
                'IV' => 4,
                'I'  => 1);

    foreach ($roman_numerals as $roman => $number) 
    {
        /*** divide to get  matches ***/
        $matches = intval($n / $number);

        /*** assign the roman char * $matches ***/
        $res .= str_repeat($roman, $matches);

        /*** substract from the number ***/
        $n = $n % $number;
    }

    /*** return the res ***/
    return $res;
    }




echo"";
echo"


";
$month = date('n');
$b=romanNumerals($month);
$years=date('Y');
echo"
"; $tanggal=date('d'); $s=mysql_query("SELECT * FROM surat_jalan WHERE identitas_surat = 1 AND bulantahun=$_POST[bulantahun] ORDER BY no_surat_jalan ASC"); while($a=mysql_fetch_array($s)){ $nomor = $a[2]; $potong = (int)substr($nomor,0,3); $potong++; } $kosong= mysql_num_rows($s); if(count($kosong) == 0){ $nomore = sprintf('%03s',1); } else { $nomore = sprintf('%03s',$potong); } echo"

No : ".$nomore."/$b/$years

Tôi đã kiểm tra mã của bạn.Tôi đã thực hiện một số thay đổi trong mã của bạn.Bạn phải sử dụng , trong mã jQuery của bạn.Đây là thay đổi "keydown, keyup".

Cũng thay đổi trong $('body').on('click', ".addmore_" + a, function (a) { trong vòng lặp for của bạn.và $('body').on("keydown, keyup", "#packinglist_"+a, function() {

Điều này là do bạn đang tạo đầu vào động

Vui lòng kiểm tra điều này, nó sẽ hoạt động:

        var i = $('table tr').length;
var count = $('table tr').length;
var row = i;
var a = 0;

for (a = 0; a <= i; a++) {
  $(".addmore_" + a).on('click', function (a) {
    return function() {
    var box = $("#box_"+ a);
    box.val( Number(box.val())+1 );

      var data = "
"; $s=mysql_query("SELECT * FROM surat_jalan order by id_surat DESC"); $a=mysql_fetch_array($s); for($i=1;$i<=$_POST['jumlahdata'];$i++) { $nomor = $a[0]; $iden = $nomor + $i; echo" "; } echo"
No Jenis Benang Warna Lot Netto Box Cones Keterangan
$i.

"; }

Bài Viết Liên Quan