2011-11-14 101 views
0

我只能在第二個表單提交後填充隱藏的div。第一次提交後出現錯誤。爲什麼?使用jQuery表單插件。任何想法?謝謝。我只能在第二個表單提交後才能填充隱藏的div。

$(document).ready(function() { 
// get ID from the form name: 
    $('form').submit(function(e){ 
    targetNum = this.name; 
// call processing page: 
    $('#formTarget' + targetNum).ajaxForm({ 
// populate DIV 
     target: '#divTarget' + targetNum, 
     success: function() { 
      $('#divTarget' + targetNum).fadeIn('slow'); 
     } 
    }); 
    }); 
}); 

<div id='divTarget1'></div> 
<form id='formTarget1' name='1' action='process2.asp' method='post'> 
<input type='hidden' name='MapaID' value='1'> 
<input type='submit' value='OK'> 
</form> 

<div id='divTarget2'></div> 
<form id='formTarget2' name='2' action='process2.asp' method='post'> 
<input type='hidden' name='MapaID' value='2'> 
<input type='submit' value='OK'> 
</form> 

<div id='divTarget3'></div> 
<form id='formTarget3' name='3' action='process2.asp' method='post'> 
<input type='hidden' name='MapaID' value='3'> 
<input type='submit' value='OK'> 
</form> 
+2

什麼是錯誤? –

+0

第一次提交數據未填充到div後,用戶可以看到處理頁面(process2.asp),而不是使用窗體和隱藏div開始頁面。 – idig

回答

0

試試這個:

$(document).ready(function() { 
    $(':submit').click(function(e) { 
     targetNum = $('form').has(this).prop('name'); 
     $('#formTarget' + targetNum).ajaxForm({ 
      target: '#divTarget' + targetNum, 
      success: function() { 
       $('#divTarget' + targetNum).fadeIn('slow'); 
      } 
     }); 
     return false; 
    }); 
}); 
+0

在'submit()'頁面重新加載發生。 'return false'語句將會停止這個頁面重新加載。 – thecodeparadox

+0

不幸的是,它不起作用,'返回false'會停止所有提交。 – idig

+0

@idig請試試這個。這可能工作。 – thecodeparadox

0

可以使用​​方法這一點。

+0

羅漢,你的意思是把.load()方法,而不是這一行:$('#formTarget'+ targetNum).ajaxForm({...我問,因爲好奇心,因爲問題似乎正在解決通過abudllah.abcoder。 – idig

+0

你可以嘗試把它。閱讀更多關於.load()在這裏:http://api.jquery.com/load/。我想我正確地得到你的問題:) – Rohan

相關問題