2013-12-10 3 views
0

안녕하세요 여러분,이 페이지는 작성하려고하는데 각 탭의 달 이름이 탭으로 표시되며 탭의 내용은 양식과 제출 버튼입니다. 내가 직면 한 문제는 예를 들어 2 월 탭의 메신저에 양식을 채운 경우 페이지를 다시 제출하면 데이터베이스에 데이터가 다시로드되고 1 월의 첫 번째 탭으로 돌아갑니다. 어떻게 그 일을 막을 수 있습니까? 제출을 클릭하고 데이터가 성공적으로 삽입 된 후 의미는 여전히 2 월 탭에 유지됩니다. 나는 onClick 속성을 가진 태그를 사용해야 만한다는 것을 알았지 만 그것은 그 것이다. 자바 스크립트에 대한 나의 지식은 최소한이다. 내용 탭의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를 사용합니다.

function handleClick(){ 
    //send the data to the server 
    $.post(/*...see jQuery documentation*/) 

    //prevent the form from submitting and the page from reloading 
    return false; 
} 

편집 : 아니면 그냥 게시 된 링크를 따라 : 당신이 jQuery를 사용하는 경우는 아약스 아주 사용하기 쉬운 것입니다 그냥 같은 솔루션을보고, D를

관련 문제