Twitter Bootstrap 模态表单提交 [英] Twitter Bootstrap Modal Form Submit
问题描述
我最近一直在摆弄 twitter bootstrap,使用 java/jboss,我一直在尝试从 Modal 界面提交表单,该表单仅包含一个隐藏字段,没有其他内容,因此显示等并不重要.
表单在模态本身之外,我只是不知道这怎么可能
我尝试将模态本身添加到表单中,尝试使用 HTML5 form="form_list" 甚至将表单添加到模态正文并使用一些 jquery 强制提交,但似乎没有任何效果
下面是我试图扩充到我需要的示例模式,之前编辑的 OK 按钮试图调用 jquery 函数.
解决方案 2018 年更新
您想在提交后关闭模态框吗?无论是模态框内的表单还是模态框外的表单,您都应该能够使用 jQuery ajax 提交表单.
这是一个示例,其中 模态框内的表单:
<a href="#myModal" role="button" class="btn" data-toggle="modal">启动演示模式</a><div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3 id="myModalLabel">模态标题</h3></div><div class="modal-body"><form id="myForm" method="post"><input type="hidden" value="hello" id="myField"><button id="myFormSubmit" type="submit">提交</button></表格></div><div class="模态页脚"><button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button><button class="btn btn-primary">保存更改</button></div></div>
还有 jQuery ajax 来获取表单字段并提交..
$('#myFormSubmit').click(function(e){e.preventDefault();alert($('#myField').val());/*$.post('http://path/to/post',$('#myForm').serialize(),功能(数据,状态,xhr){//在这里做一些响应;});*/});
<小时>I've recently been fiddling around with twitter bootstrap, using java/jboss, and i've been attempting to submit a form from a Modal interface, the form contains just a hidden field and nothing else so display etc. is unimportant.
The form is external to the modal itself, and I just can't figure out how this would be possible
i've tried adding the modal itself to the form, attempting to used HTML5 form="form_list" and even adding the form to the modal body and using some jquery to force a submit, but nothing appears to work
Below is a sample modal I was attempting to augment to what i needed, the OK button was previously editting to attempt to call jquery functions.
<div class='modal small hide fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
<h3 id='myModalLabel'>Delete Confirmation</h3>
</div>
<div class='modal-body'>
<p class='error-text'>Are you sure you want to delete the user?</p>
</div>");
<div class='modal-footer'>
<button class='btn btn-danger' data-dismiss='modal' aria-hidden='true'>Cancel</button>
<button class='btn btn-success' data-dismiss='modal'>Ok</button>
</div>
</div>
解决方案 Updated 2018
Do you want to close the modal after submit? Whether the form in inside the modal or external to it you should be able to use jQuery ajax to submit the form.
Here is an example with the form inside the modal:
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<form id="myForm" method="post">
<input type="hidden" value="hello" id="myField">
<button id="myFormSubmit" type="submit">Submit</button>
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
And the jQuery ajax to get the form fields and submit it..
$('#myFormSubmit').click(function(e){
e.preventDefault();
alert($('#myField').val());
/*
$.post('http://path/to/post',
$('#myForm').serialize(),
function(data, status, xhr){
// do something here with response;
});
*/
});
这篇关于Twitter Bootstrap 模态表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
相关文章
- Twitter Bootstrap模态表单提交;
- Twitter Bootstrap 模态表单:如何拖放?;
- Twitter Bootstrap 模态提交按钮,用于在 Rails 中提交和打开模态;
- Twitter Bootstrap 2 模态表单对话框;
- Twitter bootstrap:模态淡化;
- 如何获取Twitter Bootstrap模态以在提交表单时保持打开状态?;
- 简单的Django表单在Twitter-Bootstrap模态;
- 在表单提交中显示Twitter Bootstrap模式;
- Twitter Bootstrap模态宽度问题;
- 动态构建 Twitter Bootstrap 模态;
- 不能在Bootstrap中提交我的模态表单;
- 如何在twitter-bootstrap模态窗口中插入django表单?;
- 如何在 twitter-bootstrap 模态窗口中插入 django 表单?;
- Twitter Bootstrap模态窗体:如何拖放?;
- Twitter BootStrap 模态窗口后备链接;
- Twitter Bootstrap 模态多事件触发;
- 增加 Twitter Bootstrap 的模态大小;
- 禁止关闭Twitter Bootstrap模态窗口;
- 造型Twitter Bootstrap模态关闭图标;
- 显示模态时不会触发Twitter Bootstrap模态事件;
- Twitter Bootstrap - 内联表单;
- 以模态重新加载内容(twitter bootstrap);
- Twitter Bootstrap模态块文本输入字段;
- 模态窗口中的 Twitter Bootstrap Datepicker;
- Twitter Bootstrap模态窗口中的Datepicker;
其他开发最新文章
- 拒绝显示一个框架,因为它将'X-Frame-Options'设置为'sameorigin';
- 什么是&QUOT; AW&QUOT;在部分标志属性是什么意思?;
- 在运行npm install命令时获取'npm WARN弃用'警告;
- cmake无法找到openssl;
- 从Spark的scala中的* .tar.gz压缩文件中读取HDF5文件;
- Twitter :: Error :: Forbidden - 无法验证您的凭据;
- 我什么时候需要一个fb:app_id或者fb:admins?;
- 将.db文件导入R;
- npm通知创建一个lockfile作为package-lock.json。你应该提交这个文件;
- 拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“script-src'self'”;