2013-03-20 88 views
0

我有一個HTML格式的表單,有兩個提交按鈕,其中一個是啓用的。如果用戶正在填寫表單,則提交已啓用,另一個按鈕已被取消。 當用戶點擊提交按鈕等按鈕被激活,並讀取顯示所有的字段值只。當第二個按鈕被點擊值在DATABSE照耀處,使用jQuery的的javascript 是有可能提交後顯示值

$('input[type="text"]').each(function(){ 
      $(this).attr('readonly','readonly'); 
}); 

回答

1

如果我正確地閱讀你的問題,第一個按鈕實際上沒有提交表單?

$("#firstbutton").click(function() { 
    $("#myForm input").attr("readonly", "readonly"); //this makes the input fields readonly 

    $("#secondbutton").attr("disabled","disabled"; //this enable the second button 

    $(this).removeAttr('disabled'); //this disables the #firstbutton 
} 

確保:

  • 在頁面加載,第二個按鈕已經被禁用。
  • 如果您的表單中包含下拉列表,則您必須將其設置爲只讀,因爲它們不是<input>,而是<select>項目。
  • 第一個按鈕不應該是type="submit",它應該是type="button"或者是<button>標記。
  • 你的第二個按鈕可以是一個常規的提交按鈕,不需要任何花哨。只要您的表單發佈到正確的操作鏈接,表單將會被正常提交。
  • 從不在輸入欄中使用disabled屬性。如果你這樣做,表單提交將忽略這些字段,不會按照預期發佈。您已經在使用只讀方式正確執行此操作。
+0

我有疑問..會顯示數值 – 2013-03-20 09:27:51

+0

flater請問我該怎麼做 – 2013-03-20 09:35:55

0
$(document).ready(function(){ 
    $('#myForm').submit(function(e){ 
    e.preventDefault(); 

    $myForm = $(this); 

    $myForm.find('input[type=submit]').attr('disabled','disabled'); 
    $myForm.find('input#other-button').attr('enabled','enabled'); 


    //do a $.post request 
    $.post('/path/to/my-file.php', 
      $myForm.serialize(), 
      function(data){ 
      // make something after the post is complete 
      $myForm.find("input[type=text]").attr('readonly','readonly'); 
      }, 
      'json'); 
    }); 
}); 
+0

我有疑問..會顯示回數值 – 2013-03-20 09:53:59