onclickjquery可以在不重新加载页面的情况下提交表单
onclick jquery to submit form without reloading the page
嘿,伙计们,所以我试图创建的这个页面有每个选项卡的月份名称,选项卡的内容是一个表单和一个提交按钮。例如,我面临的问题是,如果我在二月选项卡上,我已经填写了表格,当我单击提交时,页面会重新加载(数据插入数据库),并返回到第一个选项卡,即一月。我该如何阻止这种情况的发生?这意味着在点击提交并成功插入数据后,它仍然停留在二月选项卡上。我读到我必须使用带有onClick属性的标签,但仅此而已。我对javascript的了解微乎其微。
带有内容的选项卡的一部分:
<div class="tabContent" id="feb">
<form method="post" action="income.php">
<input type="hidden" name="feb" value="February">
<center><h2>February </h2></center>
<div>
<div style="height:0px;">
<div class="rmtotal">
<h3>Your Total Income :</br> RM <input type="text" id="febtotal"
name="febtotal" size="11" readonly value="<?php if(@$fsql) {echo
htmlentities(@$fprev['total']);} if(isset($_POST['febtotal']))
{echo htmlentities($_POST['febtotal']);}?>" ></h3>
</div>
<input type="submit" value="Save" class="save" name="febsave">
<button type="submit" class="prev" name="febprev" id="button"
onClick="">Select from previous Month</button>
</div>
<table border="1" rules="groups" cellpadding="10px;" class="tableincome">
<thead>
<th>Monthly Salary</th>
<th></th>
<th>RM</th>
</thead>
<tr>
<td>Basic Salary</td>
<td></td>
<td><center><input type="text" class="feb" placeholder="0"
name="febbasic" size="11" value="<?php if(@$fsql) {echo
htmlentities(@$fprev['basic']);} if(isset($_POST['febbasic'])){echo
htmlentities($_POST['febbasic']);}?>"></center></td>
</tr>
</table>
</form>
</div>
</div>
您可以编写一个自定义函数,该函数将在有人单击提交按钮时执行。该函数需要返回false以阻止默认行为。
对于函数本身,我将使用Ajax向可以将数据存储在数据库中的服务器发送异步请求。如果您使用jQuery,那么使用Ajax将非常容易:
function handleClick(){
//send the data to the server
$.post(/*...see jQuery documentation*/)
//prevent the form from submitting and the page from reloading
return false;
}
编辑:或者只关注发布的链接:D,刚刚看到它有相同的解决方案
相关文章:
- 如何在我的情况下禁用表单提交
- 如何在不重新加载的情况下提交表单,并使用Node+Express将数据传递回同一页面
- 在不使用PHP的情况下将表单输入值获取到Javascript中
- 一个具有两个图像按钮的表单在只能按下一个按钮的情况下发送两个按钮值
- 如何在没有按钮的情况下提交表单
- 表单验证工作不正常,在不检查条目的情况下继续
- 如何在不提交表单的情况下使用jQuery.validate
- 如何在没有表单提交、没有js、没有jquery和没有ajax的情况下将输入的文本框值存储到php变量中
- 如何在不刷新页面的情况下每次单击一组选项卡时刷新视图内容窗格
- 单输入表单 - 特殊情况 |停止表单提交
- 如何在不刷新页面的情况下发送表单
- Ember:在没有硬编码的情况下在页面加载时锁定表单“;禁用”;
- 如何在不打开新窗口的情况下在单页应用中执行 Dropbox 身份验证
- Chrome HTML document.execCommand('inserthtml' 插入到下表单
- 按下表单重置按钮时删除 JavaScript 元素
- 在启用(“click”)的情况下获取单击的元素属性
- 执行任务时,tab或enter按下表单输入文本与骨干/木偶
- 为什么变量在一种情况下用单引号发送,而在另一种情况下不加引号
- 在不使用全局作用域的情况下,单击将数字推送到Array
- 在没有命名空间的情况下引用单例体到单例体,但是如何