我如何提交一个表单,并弹出一个警告在同一时间
How can i submit a form and pop up an alert at the same time?
. NET, MVC 4, c#, Bootstrap, Javascript)
我有一个表单来上传文件(多个),它的作品很棒,这是表单:
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<table>
<tr>
<td>Choose a filter:</td>
<td style="margin-bottom:auto">
@Html.DropDownList("filterProfile", (SelectList)ViewBag.FilterList)
</td>
</tr>
<tr>
<td>File:</td>
<td><input type="file" name="Files" id="Files" multiple /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Filter" /></td>
</tr>
</table>
}
因为上传文件可能会花费一些时间,所以我想在表单中添加一个提示我们正在处理你的文件的弹出警告会很好,所以我在提交按钮中添加了一个ID,如下所示:
<tr>
<td> </td>
<td><input type="submit" name="submit" id="alertMe" value="Filter" /></td>
</tr>
</table>
你可以看到ID是'alertMe'。
然后我在JS文件中写了这段代码:
$(function () {
$('#alertMe').click(function (e) {
e.preventDefault();
$('#processAlert').slideDown();
});
});
指的是my View(HTML)中的这一部分:
<div class="alert alert-info alert-dismissable" id="processAlert">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true" id="processAlert">×</button>
<strong>Processing...</strong> Upload files and Processing your request.
但是现在它只显示警报而不提交文件,如果我取下提交按钮的ID属性,它的工作很棒…如何使提交按钮触发两个事件?
一个事件是显示处理文件的警报。另一个事件是将文件发送到控制器中的方法。
我该怎么做呢?如果可能的话……
我最后做了什么:(immoses Answer)
我只是从脚本中删除了"preventDefault"
问题是调用prevent default会阻止表单提交。因此,添加一个调用来提交您的表单将解决这个问题。
$(function () {
$('#alertMe').click(function (e) {
e.preventDefault();
$('#processAlert').slideDown();
$('form:first').submit();
});
相关文章:
- 我确实有一个表单,如果用户输入了输入,它应该检查否定或空的输入框,并抛出一条警告消息
- React Router一直给我一个警告:你不能更改<路由器路由>
- 为什么Grunt Copy给了我一个'undefined不是函数'警告
- 在html页面的iframe中显示一个警告框
- 我如何生成一个警告/弹出窗口,说明在用户点击之前避免点击浏览器的后退按钮
- jQuery ajax async:false会导致一个奇怪的警告
- 警告:数组或迭代器中的每个子节点都应该有一个唯一的“键”道具
- 在 javascript 中动态显示一个带有换行符的警告框
- 如果当前输入有错误或警告,则禁用所有下一个表单输入字段
- 如何在没有安全警告的情况下将一个 html 加载到另一个 html 中
- 如何在Shiny中创建一个弹出窗口来警告用户选择一种类型的文件扩展名
- 为什么我会得到一个“'documentScan'不允许用于指定平台“;警告
- 如果我没有'Don’不要按写按钮,我想显示一个警告
- 我如何提交一个表单,并弹出一个警告在同一时间
- 我怎么能得到答案在同一页,而不是一个警告
- 为什么一段Javascript只有在它下面有一个警告时才能工作?
- Jshint告诉三元运算符中有一个警告
- Javascript:当一个表单被选中时显示一个警告
- 如何在javascript中显示一个警告框
- 如何使JavaScript结果出现在同一页面上,而不是在一个警告弹出窗口