4
<div class="question">
       <form id='infos' class='form' action='' style="">
               Action Description:<input type='text' class='form-control' id='action_description'></input><br/>
               Action Reponsible:<input type='text' class='form-control' id='action_responsible'></input>
               Plan Beginning date: 
               <div class='input-append date' data-date='01.01.1999' data-date-format='dd.mm.yyyy'>
               <input class='form-control' size='16' id='beginDate' name='beginDate' type='text' value='01.01.1999' >
               <span class='add-on'><i class='icon-th'></i></span>
               </div>
               End Date: 
               <div class='input-append date' data-date='01.01.1999' data-date-format='dd.mm.yyyy'>
               <input class='form-control' size='16' id='endDate' name='endDate' type='text' value='01.01.1999'>
               <span class='add-on'><i class='icon-th'></i></span>
               </div>

        </form>
    </div>

これは私のhtmlで、私のjsは次のとおりです。

var yourModal = bootbox.dialog({
                   message: $('.question').html(),
                   title: "Add Class",
                   buttons: {
                       main: {
                              label: "Save",
                              className: "btn-primary",
                              callback: function() {
                                 var type = "ACTION_SAVE";
                                 var action_description = $("#action_description").val();
                                 var action_responsible = $("#action_responsible").val();
                                 var begin_date = $("#beginDate").val();
                                 var end_date   = $("#endDate").val();


                                 console.log( action_description );
                                 console.log( action_responsible );
                                 console.log( begin_date );
                                 console.log( end_date );
                                 console.log( question_value );
                                 console.log( question_id );

                                  $.get("ActionServlet",
                                          { type: type , action_description :action_description,
                                            action_responsible : action_responsible, begin_date : begin_date,
                                            end_date : end_date, question_value:question_value, question_id:question_id
                                          },function(result){

                                              console.log(result);
                                  })

                              }
                            },
                       cancelar: {
                           label: "Close",
                           className: "btn-default"
                       }
                   },
                   show: false
               });

            yourModal.on("shown.bs.modal", function() {
                   var datepickerSelector = '.date';

                   $(datepickerSelector).datepicker();
                   $(datepickerSelector, yourModal).datepicker({
                       showOtherMonths: true,
                       selectOtherMonths: true,
                       dateFormat: "dd-mm-yyyy",
                       yearRange: '-1:+1',
                       setDate: new Date()
                   }).prev('.btn').on('click', function (e) {
                       e && e.preventDefault();
                       $(datepickerSelector, yourModal).focus();
                   });
               });

            yourModal.on("changeDate",function(ev){
                yourModal.val(ev.target.value);
            })

            yourModal.modal("show");
        }

フォームを非表示にすることから始めて、クリックすると表示されます。すべて正常に動作しますが、値を取得する必要があるフォームを送信すると、html(日付値)で提供した値しか取得できません。どうすれば修正できますか。

4

2 に答える 2

10

これを試して :

$('<your jquery selector for input>','.bootbox').val()
于 2015-05-11T09:34:42.203 に答える
1

同じ問題があり、次のように、ブートボックス ダイアログ内のテキスト入力ごとに 1 つのイベント ハンドラーを追加する必要がありました。

$(document).on('change', '#action_description', function(e) {
    $('#action_description').val($(this).val());
});

このようにして、コールバックで入力テキストの更新された値にアクセスできました。私の推測では、ブートボックスがダイアログ内の要素を混乱させ、上記のコードにより、値が DOM にとどまるように強制されます。上記が機能する理由について誰かがより詳細な説明を持っている場合は、提供してください。私は時々直感でコーディングします:P

于 2014-08-27T21:11:39.080 に答える