zoukankan      html  css  js  c++  java
  • php锁定文本框内容的方法

    有时候我们希望表单中的文本框是只读的,让用户不能修改其中的信息,如<input type="text" name="zg" value="中国"> 的内容,"中国"两个字不可以修改,有三种方法。

    方法1: onfocus=this.blur()
    <input type="text" name="zg" value="中国" onfocus=this.blur()>


    方法2:readonly
    <input type="text" name="zg" value="中国" readonly>
    <input type="text" name="zg" value="中国" readonly="true">


    方法3: disabled
    <input type="text" name="zg" value="中国" disabled>

    特别说明:使用disabled属性的话,那么提交表单时无法获得该标签的数据,即提交表单后,$zg的值为空!

    readonly只对文本域有用,disabled不仅对文本域有用,对按钮一样适用。

    下面分别是readonly和disabled的效果截图:

    ****************************************************************************************

    应用案例:

     <form action="fchmi.php" method="post"> 
         <table>
          <tr>
            <td>登录密码:</td>
            <td><input type="text" name="pwd" ></td>
            <td><i>*</i> <b>当前的登录密码</b></td>
          </tr>
          <tr>
            <td>真实姓名:</td>
            <td><input type="text" name="uname" value='<?php echo $son[uname]; ?>' <?php if($son[ustat]==1){echo readonly;} ?>></td>
            <td><i>*</i> <b>请输入您的真实姓名</b></td>
          </tr>
          <tr>
            <td>身份证号:</td>
            <td><input type="text" name="sfz" value='<?php echo $son[sfz]; ?>' <?php if($son[zstat]==1){echo readonly;} ?>></td>
            <td><i>*</i> <b>请输入您的身份证号</b></td>
           </tr>
          <tr>
            <td> </td>
            <td colspan="2"><input type="submit" value="确定"></td>
           </tr>
        </table>
    </form>

    <?php echo $son[uname]; ?>从数据库中读出姓名,当姓名修改提交后,把数据库中的ustat字段设置为1,刷新页面后,当检测到son[ustat]==1时,添加属性readonly,防止用户再次修改文本框内容。

  • 相关阅读:
    C#Mvc批量删除
    axure中使用HighCharts模板制作统计图表
    中继器的使用——搜索/分页/排序
    中继器的使用 —— 关联/增加/删除/修改数据
    axure母版使用实例之百度门户
    jdbc参数传递
    软件测试的原则
    linux中使用top获取进程的资源占用信息
    性能测试关键指标介绍
    怎样成为一个合格的测试工程师
  • 原文地址:https://www.cnblogs.com/moqiang02/p/4061564.html
Copyright © 2011-2022 走看看