Jquery 我不是';无法从Bootbox获取输入字段值
我从隐藏表单开始,然后单击显示表单,一切正常,但当我发送表单时,我应该获取值,但我只能获取html中提供的值(日期值)。如何修复它。我遇到了同样的问题,必须为引导框对话框中的每个文本输入添加一个事件处理程序,如下所示:Jquery 我不是';无法从Bootbox获取输入字段值,jquery,bootbox,Jquery,Bootbox,我从隐藏表单开始,然后单击显示表单,一切正常,但当我发送表单时,我应该获取值,但我只能获取html中提供的值(日期值)。如何修复它。我遇到了同样的问题,必须为引导框对话框中的每个文本输入添加一个事件处理程序,如下所示: var yourModal = bootbox.dialog({ message: $('.question').html(), title: "Add Class",
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");
}
通过这种方式,我可以访问回调中输入文本的更新值,我猜bootbox会弄乱对话框中的元素,上面的代码会强制该值保留在DOM中。如果有人更详细地解释了为什么上述方法有效,请提供。我有时凭直觉编写代码:P试试这个:
$(document).on('change', '#action_description', function(e) {
$('#action_description').val($(this).val());
});
$(“”,.bootbox').val()
解决方案适合我
$(document).on('change', '#action_description', function(e) {
$('#action_description').val($(this).val());
});
$('<your jquery selector for input>','.bootbox').val()