$.each()

    var btnConfirm = $('.btn-confirm');
    $.each(btnConfirm, function(index, val) {
        var that = $(this),
            thatpid = that.data('pid');

        that.on('click', function() {
            var r = confirm("确定设为已支付?");
            if (r === true) {
                var datajson = {
                    'apply_id': thatpid
                };
                $.ajax({
                        url: '/api/v4/confirm_pay',
                        type: 'POST',
                        dataType: 'json',
                        contentType: 'application/json',
                        data: JSON.stringify(datajson)
                    })
                    .done(function() {
                        console.log("success");
                        that.parent('td').prev('.data-status').removeClass('text-danger').addClass('text-success').text('已支付');//
                    })
                    .fail(function(data) {
                        alert(data.responseJSON.error_message);//
                    })
            } else {
                console.log('放弃');
                return false;
            }
        });
    });

    var toStrTime = function(e) {
        var date = new Date(e);
        Y = date.getFullYear() + '/';
        M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';
        D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
        h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
        m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
        return Y + M + D + h + m;
  };
  var datatime = $('.data-time');
  $.each(datatime, function(index, val) {
      var that = $(this);
      that.text(toStrTime(that.data('time')));
  });

results matching ""

    No results matching ""