如何将广播/复选框数据与其他字段一起添加到表单中?

时间:2017-01-03 20:55:00

标签: javascript jquery spring

我是Jquery的新手,我不知道如何在我的函数中添加几个带有其他数据类型(我的文本,数字等)的单选/复选框。我正在使用Java / Spring,它们有几个时刻:.jsp文件,spring:message等。请帮帮我!坦克。 这是我的代码:

<div class="modal fade" id="editRow">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h2 class="modal-title"><spring:message code="company.add"/></h2>
            </div>
            <div class="modal-body">
                <form:form class="form-horizontal" method="post" id="detailsForm">
                    <input type="hidden" id="id" name="id">

                    <div class="form-group">
                        <label for="name" class="control-label col-xs-3"><spring:message code="insurance.tableName"/></label>

                        <div class="col-xs-9">
                            <input type="text" class="form-control" id="name" name="name" placeholder="Name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="description" class="control-label col-xs-3"><spring:message code="insurance.tableDescription"/></label>

                        <div class="col-xs-9">
                            <input type="text" class="form-control" id="description" name="description"
                                   placeholder="Description">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="franchise" class="control-label col-xs-3"><spring:message code="insurance.tableFranchise"/></label>

                        <div class="col-xs-9">
                            <input type="number" class="form-control" id="franchise" name="franchise"
                                   placeholder="1000">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="population" class="control-label col-sm-3"><spring:message code="insurance.tablePopulation"/></label>

                        <div class="radio-inline">
                            <input type="radio" class="col-xs-2" id="population" name="population" value="Kiev"><spring:message code="insurance.kiev"/><br/>
                            <input type="radio" class="col-xs-2" id="population" name="population" value="Kiev district"><spring:message code="insurance.kievDistrict"/><br/>
                            <input type="radio" class="col-xs-2" id="population" name="population" value="more than 1 million"><spring:message code="insurance.moreOneMillion"/><br/>
                            <input type="radio" class="col-xs-2" id="population" name="population" value="to 1 million"><spring:message code="insurance.toOneMillion"/><br/>
                        </div>
                        <div class="radio-inline">
                            <input type="radio" class="col-xs-2" id="population" name="population" value="to half of 1 million"><spring:message code="insurance.toHalfAMillion"/><br/>
                            <input type="radio" class="col-xs-2" id="population" name="population" value="more than 100 thousand"><spring:message code="insurance.moreOneHundred"/><br/>
                            <input type="radio" class="col-xs-2" id="population" name="population" value="to 100 thousand"><spring:message code="insurance.toOneHundred"/><br/>
                            <input type="radio" class="col-xs-2" id="population" name="population" value="other"><spring:message code="insurance.other"/><br/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="engine_power" class="control-label col-xs-3"><spring:message code="insurance.tableEngine_Power"/></label>

                        <div class="radio-inline">
                            <input type="radio" class="col-xs-2" id="engine_power" name="engine_power" value="more than 3.0"><spring:message code="insurance.engineThree"/><br/>
                            <input type="radio" class="col-xs-2" id="engine_power" name="engine_power" value="more than 2.0"><spring:message code="insurance.engineTwo"/><br/>
                            <input type="radio" class="col-xs-2" id="engine_power" name="engine_power" value="more than 1.6"><spring:message code="insurance.engineOne"/><br/>
                            <input type="radio" class="col-xs-2" id="engine_power" name="engine_power" value="to 1.6"><spring:message code="insurance.engineToOne"/><br/>>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="amount" class="control-label col-xs-3"><spring:message code="insurance.tableAmount"/></label>

                        <div class="col-xs-9">
                            <input type="number" class="form-control" id="amount" name="amount"
                                   placeholder="1296">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-xs-offset-3 col-xs-9">
                            <button type="submit" class="btn btn-primary"><spring:message code="insurance.save"/></button>
                        </div>
                    </div>
                </form:form>
            </div>
        </div>
    </div>
</div>

我的功能:

var form;
function save() {
    form = $('#detailsForm')
    $.ajax({
        type: "POST",
        url: ajaxUrl,
        data: form.serialize(),
        success: function () {
            $('#editRow').modal('hide');
            updateTable();
            successNoty('Saved');
        }
    });
}

1 个答案:

答案 0 :(得分:0)

我已将其修复,我只是将cout << put_time(&tm, tm.tm_mday < 10 ? "%A, %B%e, %Y" : "%A, %B %e, %Y" ) << endl; 选项替换为radio,并在代码中使用不同的值,并且工作正常。