动态改变input type属性的变通方法

本文介绍了一种在网页表单中实现密码框初始状态显示为明文“请输入您的密码”,点击后变为密码输入状态的方法。通过使用两个输入框配合JavaScript实现这一效果,解决了密码框默认不支持明文提示的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4490194096475053&amp;dt=1225035063187&amp;lmt=1219829505&amp;prev_slotnames=1891601125&amp;output=html&amp;slotname=3685991503&amp;correlator=1225035063140&amp;url=http%3A%2F%2Fwww.corange.cn%2Farchives%2F2008%2F08%2F1413.html&amp;eid=30143001&amp;ea=0&amp;ref=http%3A%2F%2Fwww.corange.cn%2Fhtml%2Fcorange__72.html&amp;frm=0&amp;ga_vid=829866576.1224664711&amp;ga_sid=1225034957&amp;ga_hid=1315437805&amp;ga_fc=true&amp;flash=9.0.124.0&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_java=true" frameborder="0" width="300" scrolling="no" height="250" allowtransparency></iframe> 一个密码框,在密码框里提示输入密码,也就是"请输入您的密码"当然把这里由text设置成password,那这里value的内容都会显示*****了,我要显示明文,但是点击后,"请输入您的密码"消失,再输入的是******
type为只读属性不能改变,只能创建一个临时input来显示当光标移到时切换到实际的input中,以下是通过测试的代码:
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>zdz</title>
<scripttype="text/javascript">
functionchangeType(obj)
{
obj.style.display="none";
document.getElementById("d2").style.display="";
document.getElementById("d2").focus();
}
</script>
</head>
<body>
<divid="Edit">
<inputtype="text"id="d1"value="请输入您的密码"size="14"maxlength="20"onfocus="changeType(this);"style="display:"/>
<inputtype="password"id="d2"value=""size="14"maxlength="20"style="display:none"/>
</div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值