JS附加函数中断表单字段迭代

时间:2018-06-09 13:54:51

标签: javascript forms function append

我有一个条件函数(addAtn),如果需要,它会向动态表单附加一个额外的字段。一旦选择了项目数,就会构建主窗体。

该函数的所有元素都经过测试并且有效,但是当我尝试从ticketQuantity函数调用它时,它会中断,并且只返回1 ticketDetail行,而没有额外的附加。

addAtn函数是

                    $.get('/sellers/' + venueId + '/atn', function(data) {

                      if (data['field']=="atn") {

                        function addAtn() {
                         ticketDetails.append(
                            '<div data-row="' + i + '" class="ticket-row form-group row">' +
                            '<div class="col-md-4 col-sm-6 col-xs-6">' +
                            '<label class="control-label text-muted">UTN (unique ticket number)</label>' +
                            '<input type="text" class="form-control utn" placeholder="" name="ticket[' + i + '][utn]">' +
                            '</div>' +
                            '</div>'
                          );
                          };
                        }
                        else {
                          function addAtn() {};
                        }

                    });

select上的ticketQuantity函数是

$('#ticketQuantity').on('change', function () {
    var ticketQuantity = $('#ticketQuantity').val();
    var ticketDetails = $('#ticketDetails');
    var previewTicketBtn = $('#previewTicketBtn');

    ticketDetails.html('<p>For general admission tickets enter "GA" in Seat Number box.</p>');

    if (ticketQuantity == 1) {
        $('#split-tickets').hide();
    } else {
        $('#split-tickets').show();
    }

    $('#ticket-rows').html('');
    for (var i = 1; i <= ticketQuantity; i++) {
        ticketDetails.append('<hr><p class="ticket-details" style="margin-top: 30px;"><strong>Ticket ' + i + '</strong></p>' +
             '<div data-row="' + i + '" class="ticket-row form-group row">' +
             '<div class="col-md-2 col-sm-6 col-xs-6">' +
             '<label class="control-label text-muted">Seat number</label>' +
             '<a href="#" data-tooltip="Please enter the Section, Row and Seat number exactly as it appears on your ticket">?</a>' +
             '<input type="text" class="form-control seatNumber" placeholder="" name="ticket[' + i + '][seat_number]">' +
             '</div>' +
             '<div class="col-md-2 col-sm-6 col-xs-6">' +
             '<label class="control-label text-muted">Ticket face value</label>' +
             '<div class="input-group">' +
             '<span class="input-group-addon">£</span>' +
             '<input type="text" class="form-control ticketFaceValue" name="ticket[' + i + '][ticket_face_value]">' +
             '</div>' +
             '</div>' +
             '<div class="col-md-2 col-sm-6 col-xs-6">' +
             '<label class="control-label text-muted">Asking price</label>' +
             '<div class="input-group">' +
             '<span class="input-group-addon">£</span>' +
             '<input type="text" class="askingPrice last-ticket-input form-control" name="ticket[' + i + '][asking_price]">' +
             '</div>' +
             '</div>' +
             '</div>' +
             '<div data-row="' + i + '" class="ticket-row form-group row">' +
             '<div class="col-md-6" col-sm-12 col-xs-12>' +
             '<label class="control-label text-muted">Restrictions</label>' +
             '<input type="text" class="form-control restrictions" placeholder="Please enter any restrictions here, for example Child or ID required" name="ticket[' + i + '][restrictions]">' +
             '</div>' +
             '</div>');

             addAtn();

});

任何人都可以提供帮助。我无法弄清楚我做错了什么。

感谢。

0 个答案:

没有答案