PHP实现设置文本框的只读属性

一 代码

conn.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>连接数据库</title>
</head>
<body>
<?php
$conn=mysql_connect("localhost","root","root");		//连接数据库服务器
mysql_select_db("db_database24",$conn);				//连接db_database08数据库
mysql_query("set names utf8");						//设置数据库编码格式
?>
</body>
</html>
 
index.php
<?php include("conn.php");?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>设置文本框的只读属性</title>
<style type="text/css">
<!--
.style1 {font-size: 12px}
.style2 {font-size: 13px}
-->
</style>
</head>
<body>
<table width="300" border="1" cellpadding="0" cellspacing="0" background="images/hhh.JPG">
<?php 
include("conn.php");
$query=mysql_query("select * from tb_stock");
$myrow=mysql_fetch_array($query);
?>
<form name="form1" method="post" action="">
  <tr>
    <td height="22" colspan="4" align="center" class="style2">设置文本框的只读属性</td>
    </tr>
  <tr>
    <td width="67" height="22" align="center"><span class="style1">商品编号:</span></td>
    <td colspan="3">
	<input name="commodity_id" type="text" id="commodity_id" value="<?php echo $myrow['id'];?>" disabled  size="22" maxlength="50">
	</td>
  </tr>
  <tr>
    <td height="22" align="center" class="style1">商品名称:</td>
    <td colspan="3"><input name="commodity_name" type="text" id="commodity_name" value="<?php echo $myrow['name'];?>" size="22" maxlength="50"></td>
  </tr>
  <tr>
    <td height="22" align="center" class="style1">库存数量:</td>
    <td colspan="3">
     <input name="stock_count" type="text" id="stock_count" value="<?php echo $myrow['count'];?>" readonly onClick="alert('此文本框为只读属性,库存数量不能更改!')" size="22" maxlength="50"></td>
  </tr>
  <tr>
    <td height="22" align="center" class="style1">单价:</td>
    <td width="77">	
	<input name="price" type="text"class="text" id="price" value="<?php echo $myrow['price'];?>" size="10" maxlength="50"></td>
    <td width="70" align="center" class="style1">库存金额:</td>
    <td width="76"><input name="stock_money" type="text" id="stock_money" value="<?php echo $myrow['money'];?>" size="10" maxlength="50"></td>
  </tr>
  </form>  
</table>
</body>
</html>
 
二 运行结果

 
三 说明
将文本框设置成只读属性有两种方法,一种是将文本框设置成readonly,一种是将文本框设置成disabled。
  • 大小: 16.9 KB
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值