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,防止用户再次修改文本框内容。

  • 相关阅读:
    centos 安装 Lamp(Linux + Apache + PHP) 并安装 phpmyadmin
    mysql常用内置函数-查询语句中不能使用strtotime()函数!
    Windows下 wamp下Apache配置虚拟域名
    thinkphp ajax调用demo
    phpMailer 手册
    wampServer2.2 You don't have permission to access /phpmyadmin/ on this server.
    打印对象
    最全的CSS浏览器兼容问题
    html 视频播放器
    C语言入门-结构类型
  • 原文地址:https://www.cnblogs.com/moqiang02/p/4061564.html
Copyright © 2011-2022 走看看