javascript - 如何使文本区域和img标签在单击提交按钮后只读

标签 javascript php html

<form method="post" enctype="multipart/form-data" action="">
<div class="prp_div">   
<div id="img_div1"> 
<?php
include_once('config.php');


$disp=mysql_query("select * from pop") ;
$out = mysql_fetch_array($disp);
?>
<img src="<?php echo $out[3];?>" style="width:100%; height:100%" />
</div>


<div id="comment_left">

<b>Graphic Text:</b><br/>
<textarea rows="4" cols="50" id="gtext" name="gtext" placeholder="Enter Graphic Text..." class="input" >
<?php echo $out['gtext']; ?>
</textarea><br/>


<b>Caption:</b><br/>
<textarea rows="4" cols="50" id="caption" name="caption" placeholder="Enter Caption..." class="input">
 <?php echo $out['caption']; ?>
</textarea>


<input type="file" name="file">
<input type="submit" name="submit" value="save">     

我有一个表单,其中包含一个 div 中的图像标签和两个文本区域。一旦我输入数据并按下提交按钮,我希望这些字段为只读。任何人都可以帮助我完成此任务。

最佳答案

使用 PHP 变量。

<?php
    $isSubmitted = false;
   if (!empty($_POST))//checks request
        $isSubmitted = true;

?>

<!--on your textarea-->
<textarea rows="4" cols="50" id="caption" name="caption" placeholder="Enter Caption..." class="input" 
<?php
    echo $isSubmitted== true? 'disabled' : '' //add 'disabled' tag in element if isSubmitted is true
 ?>
><?php echo $out['caption']; ?></textarea>

抱歉,如果我的代码有点脏。

编辑

仅此一项可能会起作用。

<!--on your textarea-->
<textarea rows="4" cols="50" id="caption" name="caption" placeholder="Enter Caption..." class="input" 
<?php
    echo !empty($out['caption'])? 'disabled' : '' //add 'disabled' tag in element if $out['caption'] is not empty
 ?>
><?php echo $out['caption']; ?></textarea>

关于javascript - 如何使文本区域和img标签在单击提交按钮后只读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28758894/

相关文章:

javascript - 从错误中恢复

php - 使用 CSS 风格化分页控件

android - TextView 为 <li> 标签呈现丑陋的项目符号

html - 将 css 样式应用于 html 帮助程序

javascript - 如何使用 javascript 检查 webkitdirectory 是否正常工作?

javascript - Openlayers 在 OpenStreetMaps 图层上圈出多边形

javascript - 如何使用firebug查看实时JS调用

php - OctoberCMS:如何通过添加或编辑RelationController来扩展 Controller ?

php - 使用 JavaScript 去除斜线?可能的

html - css hover 影响不相关的元素