Javascript 如何将表单输入的属性更改为禁用=";假;“制作后”;“真的”;

Javascript 如何将表单输入的属性更改为禁用=";假;“制作后”;“真的”;,javascript,ajax,twitter-bootstrap,Javascript,Ajax,Twitter Bootstrap,我有一个通过Ajax提交的表单。用户发送表单后,文本将发生变化,显示数据已成功发送,然后显示已填写的表单。我想显示表单,但我不想让他们重新提交表单,所以我想禁用输入以及提交按钮。我有3个操作,添加、更新和查看。在视图中禁用表单输入后,在add中保持禁用状态 <div id="userModal" class="modal fade"> <div class="modal-dialog"> <form method="post" id="user_form" e

我有一个通过Ajax提交的表单。用户发送表单后,文本将发生变化,显示数据已成功发送,然后显示已填写的表单。我想显示表单,但我不想让他们重新提交表单,所以我想禁用输入以及提交按钮。我有3个操作,添加、更新和查看。在视图中禁用表单输入后,在add中保持禁用状态

<div id="userModal" class="modal fade">
 <div class="modal-dialog">
  <form method="post" id="user_form" enctype="multipart/form-data">
   <div class="modal-content">
    <div class="modal-header">
     <button type="button" class="close" data-dismiss="modal">&times;</button>
     <h4 class="modal-title">Add Report</h4>
    </div>
    <div class="modal-body">
     <div class="row">
     <div class="col-xs-2">
         <label for="ex1">Square</label>
         <input type="text" name="square" id="square" class="form-control">
     </div>
     <div class="col-xs-2">
         <label for="ex1"> Number </label>
         <input type="text" name="report_number" id="report_number" class="form-control">
     </div>
     <div class="col-xs-4">
         <label>Report Date </label>
         <input type="date" name="report_date" id="report_date" class="form-control" />
     </div >
     </div>

     </br>

     <div class="row">
      <div class="col-xs-12">
         <label>Notes </label>
         <textarea rows="15" cols="80" type="text" name="notes" id="notes" class="form-control" > </textarea>
     </div >
     </div>

     <br />
     <label>Select Image</label>
     <input type="file" name="user_image" id="user_image" />
     <span id="user_uploaded_image"></span>
    </div>
    <div class="modal-footer">
     <input type="hidden" name="report_id" id="report_id" />
     <input type="hidden" name="operation" id="operation" />
     <input type="submit" name="action" id="action" class="btn btn-success" value="Add" />
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    </div>
   </div>
  </form>
 </div>
</div>


<script>

 $(document).on('submit', '#user_form', function(event){
  event.preventDefault();

  var addedSquare = $('#square').val();
  var addedNumber = $('#report_number').val();
  var addedDate = $('#report_date').val();
  var extension = $('#user_image').val().split('.').pop().toLowerCase();
  if(extension != '')
  {
   if(jQuery.inArray(extension, ['gif','png','jpg','jpeg']) == -1)
   {
    alert("Invalid Image File");
    $('#user_image').val('');
    return false;
   }
  } 
  if(addedSquare != '' && addedNumber != '')
  {
   $.ajax({
    url:"insert.php",
    method:'POST',
    data:new FormData(this),
    contentType:false,
    processData:false,
    success:function(data)
    {

     alert(data);
     $('#user_form')[0].reset();
     $('#userModal').modal('hide');

     dataTable.ajax.reload();
    }
   });
  }
  else
  {
   alert("Both Fields are Required");
  }
 });

 $(document).on('click', '.update', function(){
  var report_id = $(this).attr("id");
  $.ajax({
   url:"fetch_single.php",
   method:"POST",
   data:{report_id:report_id},
   dataType:"json",
   success:function(data)
   {
    $('#userModal').modal('show');
    $('#square').val(data.square).prop( "disabled", false );
    $('#report_number').val(data.report_number).prop( "disabled", false );
    $('#report_date').val(data.report_date).prop( "disabled", false );
    $('.modal-title').text("Edit Report");
    $('#report_id').val(report_id);
    $('#user_uploaded_image').html(data.user_image);
    $('#action').val("Edit");
    $('#operation').val("Edit");
   }
  })
 });

 $(document).on('click', '.view', function(){
  var report_id = $(this).attr("id");
  $.ajax({
   url:"fetch_single.php",
   method:"POST",
   data:{report_id:report_id},
   dataType:"json",
   success:function(data)
   {
    $('#userModal').modal('show');
    $('#square').val(data.square).prop( "disabled", true );
    $('#report_number').val(data.report_number).prop( "disabled", true );
    $('#report_date').val(data.report_date).prop( "disabled", true );
    $('.modal-title').text("View Report");
    $('#report_id').val(report_id);
    $('#user_uploaded_image').html(data.user_image);
    $('#action').val("View");
    $('#operation').val("View");
   }
  })
 });


</script>

&时代;
添加报告
广场
数
报告日期

笔记
选择图像 接近 $(文档).on('submit','user#u form',函数(事件){ event.preventDefault(); var addedSquare=$('#square').val(); var addedNumber=$(“#报告编号”).val(); var addedDate=$(“#报告日期”).val(); 变量扩展=$('#user_image').val().split('.').pop().toLowerCase(); 如果(扩展名!='') { if(jQuery.inArray(扩展名,['gif'、'png'、'jpg'、'jpeg'])=-1) { 警报(“无效图像文件”); $(“#用户_图像”).val(“”); 返回false; } } if(addedSquare!=''&&addedNumber!='') { $.ajax({ url:“insert.php”, 方法:'POST', 数据:新表单数据(本), contentType:false, processData:false, 成功:功能(数据) { 警报(数据); $('user_form')[0].reset(); $('#userModal').modal('hide'); dataTable.ajax.reload(); } }); } 其他的 { 警报(“两个字段均为必填项”); } }); $(文档)。在('单击','更新',函数()上){ var报告_id=$(此).attr(“id”); $.ajax({ url:“fetch_single.php”, 方法:“张贴”, 数据:{report_id:report_id}, 数据类型:“json”, 成功:功能(数据) { $('userModal').modal('show'); $('#square').val(data.square).prop(“禁用”,false); $('#报告编号').val(数据.报告编号).prop(“已禁用”,false); $('#report_date').val(data.report_date).prop(“disabled”,false); $('.modal title')。文本(“编辑报告”); $('#report_id').val(report_id); $('#user_uploaded_image').html(data.user_image); $('动作').val(“编辑”); $(“#操作”).val(“编辑”); } }) }); $(文档)。在('单击','查看',函数()上){ var报告_id=$(此).attr(“id”); $.ajax({ url:“fetch_single.php”, 方法:“张贴”, 数据:{report_id:report_id}, 数据类型:“json”, 成功:功能(数据) { $('userModal').modal('show'); $('#square').val(data.square).prop(“disabled”,true); $(“#报告编号”).val(data.report_编号).prop(“disabled”,true); $('#report_date').val(data.report_date).prop(“disabled”,true); $('.modal title')。文本(“查看报告”); $('#report_id').val(report_id); $('#user_uploaded_image').html(data.user_image); $('动作').val(“视图”); $('操作').val(“视图”); } }) });

如何在add中再次启用输入?

just.prop(“disabled”,false)

just.prop(“禁用”,false)

您使用的是
.prop(“disabled”,true)
要禁用它们,
.prop(“禁用”,false)无法再次启用它们?添加.prop时(“禁用”,true);到视图模式,然后在add模式中输入保持禁用状态,我尝试添加.prop(“disabled”,false);添加模式,但仍禁用该函数(),如果代码中没有该函数,请尝试编辑您的问题(请使用简化版本,不包含所有ajax内容)。您使用的是
.prop(“disabled”,true)
要禁用它们,
.prop(“禁用”,false)无法再次启用它们?添加.prop时(“禁用”,true);到视图模式,然后在add模式中输入保持禁用状态,我尝试添加.prop(“disabled”,false);添加到add模式,但仍然禁用函数works(),如果您的代码中没有该函数,请尝试编辑您的问题(如果没有所有ajax内容,请使用简化版本)。