2013-12-10 158 views
0

嘿家伙所以这个页面即时通讯尝试创建具有每个标签的月份名称的标签和标签的内容是一个表单和提交按钮。例如,即时通讯面临的问题是,如果即时通讯在二月份的标签页上,我填写了表格,当我点击提交页面重新载入(数据插入到数据库)并返回到一月份的第一个标签。我如何阻止这种情况发生?这意味着点击提交并且数据插入成功后,它仍然保留在二月份选项卡上。我读过,我必须使用onClick属性的标签,但多数民众赞成在它。我的JavaScript知识很少。与内容标签的onclick jquery提交表单,无需重新加载页面

部分:

   <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> 

回答

0

您可以编写当有人点击提交按钮将要执行的自定义功能。 该函数需要返回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,刚看到它具有相同的解决方案

相关问题