2013-03-20 107 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