无法提交隐藏的输入值 [英] can not submit value of input hidden
问题描述
我有一个这样的表格:
$(document)。 ready(function(){$('#create_lop_monhoc_modal')。on('show.bs.modal',function(event){var button = $(event.relatedTarget)var tenmh = button.data('tenmh')var mamh = button.data('mamh')var modal = $(this)modal.find('#input_tenmh')。val(tenmh).trigger(change)modal.find('#tenmh')。text( tenmh).trigger(change)modal.find('#input_mamh')。val(mamh).trigger(change)})});
< pre class =snippet-code-html lang-html prettyprint-override> < script src =https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery .min.js>< / script>< link href =https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css\"rel =stylesheet/> < script src =https://stackpath.bootstr apcdn.com/bootstrap/4.1.3/js/bootstrap.min.js\"></script><div class =modal fadeid =create_lop_monhoc_modal> < div class =modal-dialog modal-dialog-centered> < div class =modal-content> < form action =/ monhocmethod =POST> < input type =hiddenvalue =id =input_mamhname =mamh/> < input type =hiddenvalue =id =input_tenmhname =tenmh/> < div class =modal-body> < h4 id =mamh>< / h4> < DIV> < div class =modal-footer> < button type =submitclass =btn btn-success> Crate< / button> < / DIV> < / DIV> < / DIV> < /形式> < / DIV> < / div>< / div>< button type =buttondata-toggle =modaldata-target =#create_lop_monhoc_modaldata-tenmh =tenmhdata-mamh =mamh>打开模态< /按钮>
当我点击打开模态时,输入隐藏的值被放置,但是当我提交该表单时,它的值不提交。当我点击浏览器的后退按钮并再次提交时,这提交成功!。
我不知道为什么,请帮助!!
我认为我的问题是由另一个javascript库引起的,即由于bootstrap-datepicker.js。因为当我点击datepicker输入时,它的值被重置。
我通过删除datepicker解决了这个问题并再次尝试提交,它正在运行。
在我的问题中,我认为我认为不再需要.trigger(更改):
modal .find('#input_tenmh')。val('tenmh')。触发器(更改)
modal.find('#tenmh')。text('tenmh')。触发器(更改)
modal.find('#input_mamh')。val('mamh')。触发器(更改)
之后:
modal.find('#input_tenmh')。val('tenmh')
modal.find('#tenmh')。text('tenmh')
modal.find('#input_mamh')。val('mamh')
感谢所有人!
I have a form like this:
$(document).ready(function() {
$('#create_lop_monhoc_modal').on('show.bs.modal', function(event) {
var button = $(event.relatedTarget)
var tenmh = button.data('tenmh')
var mamh = button.data('mamh')
var modal = $(this)
modal.find('#input_tenmh').val(tenmh).trigger("change")
modal.find('#tenmh').text(tenmh).trigger("change")
modal.find('#input_mamh').val(mamh).trigger("change")
})
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<div class="modal fade " id="create_lop_monhoc_modal">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<form action="/monhoc" method="POST">
<input type="hidden" value="" id="input_mamh" name="mamh" />
<input type="hidden" value="" id="input_tenmh" name="tenmh" />
<div class="modal-body">
<h4 id="mamh"></h4>
<div>
<div class="modal-footer">
<button type="submit" class="btn btn-success">Crate</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<button type="button" data-toggle="modal" data-target="#create_lop_monhoc_modal" data-tenmh="tenmh" data-mamh="mamh">
Open Modal
</button>
When i click 'Open Modal', the value of input hidden was put, but when i submit that form, the value of it is not submit. when i click back button of browser and submit again, this submit success!.
I dont know why, please help!!
I think my problem is caused by another javascript library, namely due to bootstrap-datepicker.js. Because when i click datepicker input, value of it is reset.
I solved this problem by remove datepicker and try submit again, and it is working. In my question, i think I think that .trigger("change") is no longer needed:
modal.find('#input_tenmh').val('tenmh').trigger("change")
modal.find('#tenmh').text('tenmh').trigger("change")
modal.find('#input_mamh').val('mamh').trigger("change")
after that:
modal.find('#input_tenmh').val('tenmh')
modal.find('#tenmh').text('tenmh')
modal.find('#input_mamh').val('mamh')
Thank for all!
这篇关于无法提交隐藏的输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!