提交表单后如何使文本字段不可编辑

时间:2018-10-22 12:19:38

标签: javascript php jquery html

在提交表单之前,提交的文本将是可编辑的?

<div class="container">
  <form method="POST" name="requests" id="signup">
    <input type="text" id="txtTitle" name="txtTitle" placeholder="Enter Your Description" required="" value="<?php if (isset($_POST['txtTitle'])) { echo $_POST['txtTitle'];}?>" >
    <button type="submit" value='Submit'  class="sendButton" name="submit" id='submitme'>Submit</button>
  </form>
</div>

2 个答案:

答案 0 :(得分:-1)

只需使用readonly

<div class="container">
  <form method="POST" name="requests" id="signup">
    <input type="text" id="txtTitle" name="txtTitle" placeholder="Enter Your Description" required="" value="<?php if (isset($_POST['txtTitle'])) { echo $_POST['txtTitle'];}?>" <?php echo isset($_POST['txtTitle']) ? "readonly" : "" ?> >
    <button type="submit" value='Submit'  class="sendButton" name="submit" id='submitme'>Submit</button>
  </form>
</div>

答案 1 :(得分:-1)

尝试一下:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  <form method="POST" name="requests" id="signup">
  <input type="hidden" value="yes" name="send">
    <input type="text" id="txtTitle" name="txtTitle" placeholder="Enter Your Description" required="" value="<?php if (isset($_POST['txtTitle'])) { echo $_POST['txtTitle'];}?>" <?php echo isset($_POST['txtTitle']) ? "readonly" : "" ?> >
    <button type="submit" value='Submit'  class="sendButton" name="submit" id='submitme'>Submit</button>
  </form>
</div>

<script type="application/javascript">
$(document).ready(function(){
 <?
 //
 echo "var send='". $_POST['send']."';";
 ?>
 if(send=="yes"){
 $('#txtTitle').attr('disabled','disabled');
 };


});

</script>