JS点击文本框改变背景颜色

代码如下:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>文本框获焦点改变背景颜色</title>
	</head>
	<body>
		<table align="center"width="337" height="204"border=()>
		<tr>
			<td width="108">用户名</td>
		<td width="213"><form name="form1"method="post"action="">
			<input type="text"name="textfield"onfocus="txtfocus()"onBlur="txtblur()">
		</form></td>
		</tr>
		<tr>
			<td >密码</td>
		<td ><form name="form2"method="post"action="">
			<input type="text"name="textfield2"onfocus="txtfocus()"onBlur="txtblur()">
		</form></td>
		</tr>
		<tr>
			<td >真实姓名</td>
		<td ><form name="form3"method="post"action="">
			<input type="text"name="textfield3"onfocus="txtfocus()"onBlur="txtblur()">
		</form></td>
		</tr>
		<tr>
			<td >性别</td>
		<td ><form name="form4"method="post"action="">
			<input type="text"name="textfield5"onfocus="txtfocus()"onBlur="txtblur()">
		</form></td>
		</tr>
		<tr>
			<td >邮箱</td>
		<td ><form name="form5"method="post"action="">
			<input type="text"name="textfield4"onfocus="txtfocus()"onBlur="txtblur()">
		</form></td>
		</tr>
		</table>
		<script language="JavaScript">
			<!--
			function txtfocus(event){
				var e=window.event;
				var obj=e.srcElement;
				obj.style.background="#FF9966";
			}
			function txtblur(event){
				var e=window.event;
				var obj=e.srcElement;
				obj.style.background="#FFFFFF";
			}
			//-->
		</script>
		
	</body>
</html>

结果如图:
略
略

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值