修改input输入框的type属性_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 12:12:05
原创
1163人浏览过

<ul class="login_list"  id="web_login">                <li class="login_input">                    <input id="u" name="u"  tabindex="2" class="input_txt" type="text" value="User name" onFocus="this.value=''" onBlur="if(!value){value=defaultValue;}" />                </li>                <li class="login_input">                    <input type="text" class="input_txt2" value="Password" onfocus="if(this.value==defaultValue) {this.value='';this.type='password'}" onblur="if(!value) {value=defaultValue; this.type='text';}" />                </li></ul>
登录后复制


想要实现当鼠标焦点放在两个输入框上面的时候将输入框置空,但是清除密码的时候出了一个问题,用户输入的密码应该是 ”*****”,在IE8下确没有效果,请大侠来帮我解决一下吧,谢谢了

图改改
图改改

在线修改图片文字

图改改 455
查看详情 图改改

回复讨论(解决方案)

type是只读属性,不可以修改的。
只能这样了

<script type="text/javascript"> function changeType(obj) {     obj.style.display = "none";     document.getElementById("d2").style.display = "";     document.getElementById("d2").focus(); } </script>
登录后复制

<ul class="login_list"  id="web_login">    <li class="login_input">        <input id="u" name="u"  tabindex="2" class="input_txt" type="text" value="User name" onFocus="this.value=''" onBlur="if(!value){value=defaultValue;}" />    </li>    <li class="login_input">        <input type="text" class="input_txt2" value="Password" onfocus="changeType(this)" onblur="if(!value) {value=defaultValue; this.type='text';}" />	<input type="password" class="input_txt2" id="d2" value="" style="display:none" />     </li></ul>
登录后复制

只读属性,怎能修改呢?

密码框框肯定是用type=“password”

刷新·············································

type是只读属性,不可以修改的。
只能这样了
JScript code

<script> <br /> function changeType(obj) { <br /> obj.style.display = "none"; <br /> document.getElementById("d2").style.display = ""; <br /> docum…… <br /> <br /> 我已找到解决办法了,和楼主的一样,学习了,谢谢哈 </script>

<input name="" type="text" value="Password" class="inputText_1" id="tx"  /><input name="" type="password" style="display:none;" id="pwd" class="inputText_1" />
登录后复制


<script type="text/javascript">var tx = document.getElementById("tx"), pwd = document.getElementById("pwd");tx.onfocus = function(){if(this.value != "Password") return;this.style.display = "none";pwd.style.display = "";pwd.value = "";pwd.focus();}pwd.onblur = function(){if(this.value != "") return;this.style.display = "none";tx.style.display = "";tx.value = "Password";}</script>
登录后复制


有遇到过类似问题的朋友可以参考一下

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号