php-提交表单时,引导程序模式会打开,但是单击“确定”按钮时,它将不起作用
作者:互联网
我有一种用php代码更新mysqli数据库的表格.代码很好,当我提交表单时,数据库更新就可以了.但是我想在提交表单之前收到确认引导程序模式.为此,我使用了以下代码.模态在这里打开,但是当单击“确定”按钮时,它不起作用.
<button class="btn btn-danger btn-lg" name="submit" value="submit" type="submit" data-condition="salaryinfo" data-toggle="modal-confirm" data-message="Are you sure?" data-title="Hi you!" data-target="#submit-confirm">Submit</button>
</form>
<!-- Modal -->
<div class="modal fade" id="submit-confirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title"></h4>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" data-confirm="modal">OK</button>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-1.12.0.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.min.js"></script>
<!-- For modal -->
<script src="js/confirm-bootstrap.js"></script>
<script type="text/javascript">
function salaryinfo(){
return true;
};
$(document).ready(function(){
//modal delete confirm
$('button[data-toggle="modal-confirm"]').click(function(event) {
event.preventDefault();
var self = $(this);
var message = self.data('message');
var title = self.data('title');
var target = $(self.data('target'));
var condition = self.data('condition');
if( target.length == 1) {
target.find('.modal-title').html(title);
target.find('.modal-body').html(message);
var showModal = true;
var fn = window[condition];
if(typeof fn === 'function') {
showModal = fn(condition);
}
if( showModal ) {
target.on('shown.bs.modal', function(e) {
target.find('button[data-confirm="modal"]').click(function(e){
e.preventDefault();
var parentForm = self.closest('form');
console.log(parentForm.html());
if( parentForm.length == 1 ) {
parentForm.submit();
}
});
});
target.modal({ show: true });
};
};
});
});
</script>
对工作方式有什么建议吗?
解决方法:
您已经在提交模式之前提交了表单,因为您的按钮具有提交值:
< button class =“ btn btn-danger btn-lg” name =“ submit” value =“ submit” type =“ submit” data-condition =“ salaryinfo” data-toggle =“ modal-confirm” data-message =“你确定吗?” data-title =“嗨,你好!” data-target =“#submit-confirm”> Submit< / button>
因此,只需将带有数据的普通按钮切换到模态即可.
然后在您的模式上单击确认按钮,以具有提交的值.
您还需要在< form> < / form>
标签:bootstrap-modal,php,jquery 来源: https://codeday.me/bug/20191118/2031133.html