<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中提供的值(日期值)如何修复它
答案 0 :(得分:8)
试试这个:
$('<your jquery selector for input>','.bootbox').val()
答案 1 :(得分:1)
我遇到了同样的问题,不得不为bootbox对话框中的每个文本输入添加一个事件处理程序,如下所示:
$(document).on('change', '#action_description', function(e) {
$('#action_description').val($(this).val());
});
这样我就能够在回调中访问输入文本的更新值,我的猜测是bootbox混淆了对话框中的元素,上面的代码强制值保留在DOM中。如果有人对上述原因的解释有更详细的解释,请提供。我有时直觉编码:P